load_module for loading packages

2013-12-11 Thread Sergey
Hi, If I use load_module for loading module, I can instantiate classes, defined in that module. Is it possible to do the same, if load not a module, but package? Python documentation for load_module contains description, that load_module can load a package. But I can not find examples, how to

Using Python inside Programming Without Coding Technology (PWCT) environment.

2013-12-11 Thread msfclipper
Hello Article : Using Python inside Programming Without Coding Technology (PWCT) environment. http://www.codeproject.com/Articles/693408/Using-Python-inside-Programming-Without-Coding-Tec In this article you will find information about using Python in the PWCT Visual Programming Environment

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Devin Jeanpierre
On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman et...@stoneleaf.us wrote: Doesn't sound like they do, as that's causing plenty of problems. In today's world that level of knowledge isn't always necessary, especially if your degree is not in CS. One of the (many) nice things about Python is one

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Wed, Dec 11, 2013 at 7:34 PM, Devin Jeanpierre jeanpierr...@gmail.com wrote: On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman et...@stoneleaf.us wrote: Doesn't sound like they do, as that's causing plenty of problems. In today's world that level of knowledge isn't always necessary, especially

Differences between obj.attribute and getattr(obj, attribute)

2013-12-11 Thread Johannes Schneider
Hi list, can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx

Re: Differences between obj.attribute and getattr(obj, attribute)

2013-12-11 Thread Jurko Gospodnetić
Hi. On 11.12.2013. 9:23, Johannes Schneider wrote: can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? You can not use obj.attribute if you have the word 'attribute'

Re: Differences between obj.attribute and getattr(obj, attribute)

2013-12-11 Thread Chris Angelico
2013/12/11 Johannes Schneider johannes.schnei...@galileo-press.de: can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? You use getattr when the attribute name comes from a

Re: Differences between obj.attribute and getattr(obj, attribute)

2013-12-11 Thread Chris Angelico
On Wed, Dec 11, 2013 at 8:30 PM, Jurko Gospodnetić jurko.gospodne...@pke.hr wrote: Also, you can not test whether an object has an attribute when using the object.attribute access method without raising/catching an exception and then it can be hard to make sure no other code caused the

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread wxjmfauth
A few practical considerations, far away from theoretical aspects. Mainly for non ascii, understand non native English speakers. Python is an ascii oriented product. Platform. On Windows, the solely version which works harmoniously with the system is Py 2.7 in a byte string mode (ie non

Re: python import error

2013-12-11 Thread Mark Lawrence
On 11/12/2013 05:45, smilesonisa...@gmail.com wrote: On Wednesday, December 11, 2013 10:23:34 AM UTC+5:30, John Gordon wrote: In 93405ea9-6faf-4a09-9fd9-ed264e313...@googlegroups.com smilesonisa...@gmail.com writes: File aaa.py, line 5, in module from ccc.ddd import sss

Is there any advantage to using a main() in python scripts?

2013-12-11 Thread JL
Python scripts can run without a main(). What is the advantage to using a main()? Is it necessary to use a main() when the script uses command line arguments? (See script below) #!/usr/bin/python import sys def main(): # print command line arguments for arg in sys.argv[1:]:

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Mark Lawrence
On 11/12/2013 09:39, wxjmfa...@gmail.com wrote: A few practical considerations, far away from theoretical aspects. Mainly for non ascii, understand non native English speakers. Python is an ascii oriented product. Sheer unadulterated rubbish. Platform. On Windows, the solely version which

Re: Differences between obj.attribute and getattr(obj, attribute)

2013-12-11 Thread Johannes Schneider
thank you guys. On 11.12.2013 10:36, Chris Angelico wrote: 2013/12/11 Johannes Schneider johannes.schnei...@galileo-press.de: can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread Ben Finney
JL lightai...@gmail.com writes: Python scripts can run without a main(). What is the advantage to using a main()? Modular code – that is, implementing the program functionality in small, well-defined units with narrow, strictly-defined interfaces – is good design. Practical benefits include

Re: Trouble with Multi-threading

2013-12-11 Thread Steven D'Aprano
On Tue, 10 Dec 2013 17:57:50 +, Walter Hurry wrote: On Tue, 10 Dec 2013 11:21:32 -0500, dan.rose wrote: PLEASE NOTE: The preceding information may be confidential or privileged. It only should be used or disseminated for the purpose of conducting business with Parker. If you are not an

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread Chris Angelico
On Wed, Dec 11, 2013 at 9:26 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: except SystemExit, exc: For new code, you'd of course want to write that as: except SystemExit as exc: which is compatible with Python 2.6, 2.7, and 3.x, while the other syntax is 2.x only. ChrisA --

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Wed, Dec 11, 2013 at 7:43 PM, Chris Angelico ros...@gmail.com wrote: When you tell a story, it's important to engage the reader from the start. On Wed, Dec 11, 2013 at 8:39 PM, wxjmfa...@gmail.com wrote: A few practical considerations, far away from theoretical aspects. Mainly for non

Re: Trouble with Multi-threading

2013-12-11 Thread Steven D'Aprano
On Tue, 10 Dec 2013 11:21:32 -0500, dan.rose wrote: I am running PYTHON 2.7.3 and executing a PYTHON program that uses multi-threading. I am running this on a 64-bit Windows 2008 R2 server (Service Pack 1). Hi Dan, and despite the emails from a few others, welcome. My further comments

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 19:43:52 +1100, Chris Angelico wrote: [1] http://tvtropes.org/pmwiki/pmwiki.php/Main/InMediasRes TV Tropes? You utter, utter bastard. Must... resist... call... of... TV Tropes... -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Steve Simmons
On 11/12/2013 11:45, Chris Angelico wrote: And then, shortly after the beginning of the story, you need to introduce the villain. Thanks, jmf, for taking that position in our role-play storytelling scenario! A round of applause for jmf, folks, for doing a brilliant impression of the

mush 1.2 released! - Type-based dependency injection for scripts

2013-12-11 Thread Chris Withers
Hi All, I'm very happy to announce the a new release of Mush, a light weight dependency injection framework aimed at enabling the easy testing and re-use of chunks of code that make up scripts. This release rounds out a some more rough edges after even more real world use: - The 'nothing'

Re: Trouble with Multi-threading

2013-12-11 Thread Steve Simmons
On 11/12/2013 11:37, Steven D'Aprano wrote: When did this forum become so intolerant of even the tiniest, most minor breaches of old-school tech etiquette? [... Giant Snip...] Well said Steven. I've only been member of this list for (maybe) a year, mainly lurking to learn about Python and

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tamer Higazi
Hi Dave! You were absolutely right. I don't want to iterate the entire dict to get me the key/values Let us say this dict would have 20.000 entries, but I want only those with Aa to be grabed. Those starting with these 2 letters would be only 5 or 6 then it would take a lot of time. In

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Oscar Benjamin
On 11 December 2013 08:43, Chris Angelico ros...@gmail.com wrote: On Wed, Dec 11, 2013 at 7:34 PM, Devin Jeanpierre jeanpierr...@gmail.com wrote: When you tell a story, it's important to engage the reader from the start. Sometimes that means starting the story in the middle of the action,

Script Request

2013-12-11 Thread Jeff James
Looking for a script which will check connectivity of any or all of our company URL's first thing in the morning to make sure none or our sites are down. Any suggestions ? Thank You -- https://mail.python.org/mailman/listinfo/python-list

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Wed, Dec 11, 2013 at 10:33 PM, Steve Simmons square.st...@gmail.com wrote: On 11/12/2013 11:45, Chris Angelico wrote: And then, shortly after the beginning of the story, you need to introduce the villain. Thanks, jmf, for taking that position in our role-play storytelling scenario! A

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Larry Martell
On Tue, Dec 10, 2013 at 9:16 PM, Denis McMahon denismfmcma...@gmail.com wrote: On Tue, 10 Dec 2013 20:35:47 -0500, Dennis Lee Bieber wrote: On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing greg.ew...@canterbury.ac.nz declaimed the following: That's like saying that when teaching woodwork we

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Peter Otten
Tamer Higazi wrote: Hi Dave! You were absolutely right. I don't want to iterate the entire dict to get me the key/values Let us say this dict would have 20.000 entries, but I want only those with Aa to be grabed. Those starting with these 2 letters would be only 5 or 6 then it would

Re: Script Request

2013-12-11 Thread Larry Martell
On Wed, Dec 11, 2013 at 6:53 AM, Jeff James j...@jeffljames.com wrote: Looking for a script which will check connectivity of any or all of our company URL's first thing in the morning to make sure none or our sites are down. Any suggestions ? Thank You import urllib sites =

please guide to make proxy type function in python

2013-12-11 Thread Jai
please guide to make proxy type function in python -- https://mail.python.org/mailman/listinfo/python-list

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Steve Simmons
On 11/12/2013 13:02, Chris Angelico wrote: On Wed, Dec 11, 2013 at 10:33 PM, Steve Simmons square.st...@gmail.com wrote: On 11/12/2013 11:45, Chris Angelico wrote: And then, shortly after the beginning of the story, you need to introduce the villain. Thanks, jmf, for taking that position in

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Wed, Dec 11, 2013 at 10:46 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: This definitely wouldn't work for my students but a friend of mine studied CS (at Warwick?) and his course worked as Dijkstra describes. In the first year they don't touch a real programming language or write

Figuring out what dependencies are needed

2013-12-11 Thread sal
I'm a Python beginner. I want to use it for stats work, so I downloaded Anaconda which has several of the popular libraries already packaged for Mac OS X. Now I'd like to use the backtesting package from zipline (zipline.io), but while running the test script in iPython, I receive the

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread marduk
I would agree with the previous post but also add that I've stopped calling the main function main() and usually give it a more descriptive name, such as bake_cookies() or whatever. I think that that makes it clearer what it's doing when used as a library and the 'if __name__ == '__main__'

Re: Script Request

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 04:53:41 -0700, Jeff James wrote: Looking for a script which will check connectivity of any or all of our company URL's first thing in the morning to make sure none or our sites are down. Any suggestions ? Don't reinvent the wheel, use a tool already designed for this

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tamer Higazi
Hi Peter! I got the message I know that I could have used a database. I am using for a good reason the ZODB Database. I am making things in the ZODB Database persistent, I don't like to distribute among machines. Making use of sqlite, won't give me the possibility to scale as the amount

Re: please guide to make proxy type function in python

2013-12-11 Thread Mark Lawrence
On 11/12/2013 12:28, Jai wrote: please guide to make proxy type function in python Write some code after looking at the documentation http://docs.python.org/3/. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --

Re: Figuring out what dependencies are needed

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: Now I'd like to use the backtesting package from zipline (zipline.io), .io is not normally a file extension for Python files. Are you sure that's Python code? but while running the test script in iPython, I receive the following error:

Re: Figuring out what dependencies are needed

2013-12-11 Thread Mark Lawrence
On 11/12/2013 12:44, s...@nearlocal.com wrote: I'm a Python beginner. I want to use it for stats work, so I downloaded Anaconda which has several of the popular libraries already packaged for Mac OS X. Now I'd like to use the backtesting package from zipline (zipline.io), but while running

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread rusi
Reordering to un-top-post. On 11.12.2013 06:47, Dave Angel wrote: On Wed, 11 Dec 2013 02:02:20 +0200, Tamer Higazi wrote: Is there a way to get dict by search terms without iterating the entire dictionary ?! I want to grab the dict's key and values started with 'Ar'... Your wording

Re: Figuring out what dependencies are needed

2013-12-11 Thread Robert Kern
On 2013-12-11 13:27, Steven D'Aprano wrote: On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: Now I'd like to use the backtesting package from zipline (zipline.io), .io is not normally a file extension for Python files. Are you sure that's Python code? That's a package name, not a filename.

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 12:07:08 +0200, Tamer Higazi wrote: Hi Dave! You were absolutely right. I don't want to iterate the entire dict to get me the key/values Let us say this dict would have 20.000 entries, but I want only those with Aa to be grabed. Those starting with these 2 letters

Re: Programming puzzle with boolean circuits

2013-12-11 Thread Johannes Bauer
On 09.12.2013 14:25, Chris Angelico wrote: I found this puzzle again and was thinking about: How would I code a brute-force approach to this problem in Python? Ooooh interesting! Ha, I thought so too :-) Well, here's a start: There's no value in combining the same value in an AND or an

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread Roy Smith
In article 32615c9a-b983-4399-bb55-6df6c230f...@googlegroups.com, JL lightai...@gmail.com wrote: Python scripts can run without a main(). What is the advantage to using a main()? Is it necessary to use a main() when the script uses command line arguments? (See script below)

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread Roy Smith
In article mailman.3895.1386766655.18130.python-l...@python.org, mar...@letterboxes.org wrote: I would agree with the previous post but also add that I've stopped calling the main function main() and usually give it a more descriptive name, such as bake_cookies() or whatever. I think that

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 7:47:34 PM UTC+5:30, Roy Smith wrote: JL wrote: Python scripts can run without a main(). What is the advantage to using a main()? Is it necessary to use a main() when the script uses command line arguments? (See script below) #!/usr/bin/python import

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tim Chase
On 2013-12-11 13:44, Steven D'Aprano wrote: If necessary, I would consider having 26 dicts, one for each initial letter: data = {} for c in ABCDEFGHIJKLMNOPQRSTUVWXYZ: data[c] = {} then store keys in the particular dict. That way, if I wanted keys starting with Aa, I would only

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 5:16:50 PM UTC+5:30, Oscar Benjamin wrote: The Electrical Engineering students will subsequently do low-level programming with registers etc. but at the earliest stage we just want them to think about how algorithms and programs work before going into all the

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Roy Smith
In article 3efc283f-419d-41b6-ad20-c2901c3b9...@googlegroups.com, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ I agree

Re: load_module for import entire package

2013-12-11 Thread Dave Angel
On Tue, 10 Dec 2013 23:28:31 -0800 (PST), Sergey sh0...@gmail.com wrote: def get_obj(): pkg = load_package_strict(tmp, basedir) from tmp import main return main.TTT() It is working, but if package code changes on disc at runtime and I call get_obj again, it returns instance of class,

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Grant Edwards
On 2013-12-11, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: That's like saying that when teaching woodwork we shouldn't let people use hammers, we should make them use rocks to bang nails in, because it will make them better carpenters in the long run. NAILS Nails were

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 8:16:12 PM UTC+5:30, Roy Smith wrote: rusi wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ I agree that a

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 1:44 AM, rusi rustompm...@gmail.com wrote: It is this need to balance that makes functional programming attractive: - implemented like any other programming language - but also mathematically rigorous Attractive *to the mathematician*. A more imperative style makes

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tim Chase
On 2013-12-11 09:46, Roy Smith wrote: The problem is, that doesn't make a whole lot of sense in Python. The cited implementation uses dicts at each level. By the time you've done that, you might as well just throw all the data into one big dict and use the full search string as the key. It

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread bob gailer
On 12/11/2013 4:55 AM, JL wrote: What is the advantage to using a main()? In addition to what's been said I add: It separates all the global activities: defining of functions and classes, importing modules, etc. from the doing the actual task of the program. It also ensures that the

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 8:54:30 PM UTC+5:30, Chris Angelico wrote: On Thu, Dec 12, 2013 at 1:44 AM, rusi wrote: It is this need to balance that makes functional programming attractive: - implemented like any other programming language - but also mathematically rigorous Attractive

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Neil Cerutti
On 2013-12-11, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing greg.ew...@canterbury.ac.nz declaimed the following: On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: 5) Learning to program should be painful and we should

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 2:42 AM, bob gailer bgai...@gmail.com wrote: It also ensures that the defining all the classes and functions happens before referencing them (less bookkeeping for me). These two allow me to write the main program first, and follow it with all the global stuff. I

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Mark Lawrence
On 11/12/2013 15:41, rusi wrote: When the ten becomes ten-thousand, written by a nut who's left you with code whose semantics is dependent on weird dependencies and combinatorial paths through the code you start wishing that ... he'd not been a Led Zeppelin fan, whereby every

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread bob gailer
On 12/11/2013 3:43 AM, Chris Angelico wrote: When you tell a story, it's important to engage the reader from the start...explain This is how to print Hello World to the console and worry about what exactly the console is (and how redirection affects it) Highly agree. I was once given FORTRAN

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 2:41 AM, rusi rustompm...@gmail.com wrote: Yes its always like that: When you have to figure 2 (or 10) line programs its a no-brainer that the imperative style just works. When the ten becomes ten-thousand, written by a nut who's left you with code whose semantics is

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Mark Lawrence
On 11/12/2013 00:02, Tamer Higazi wrote: Hi people! Is there a way to get dict by search terms without iterating the entire dictionary ?! Let us assume I have: {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','Arlington','Black','Arnold','Schwarzenegger'} I want to grab the dict's key

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Mark Lawrence
On 11/12/2013 16:01, bob gailer wrote: One student (PhD in Physics) looked at X = X + 1 and said no it doesn't. Someone I worked with used x := x - x - x to invert a number. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 3:01 AM, bob gailer bgai...@gmail.com wrote: One student (PhD in Physics) looked at X = X + 1 and said no it doesn't. Yeah, which is why some languages (I first met it with Pascal) spell that as X *becomes* X + 1... but regardless of what you call it, there's a

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Mark Lawrence
On 11/12/2013 16:04, Chris Angelico wrote: I strongly believe that a career programmer should learn as many languages and styles as possible, but most of them can wait. I chuckle every time I read this one. Five years per language, ten languages, that's 50 years I think. Or do I rewrite my

Re: python import error

2013-12-11 Thread John Gordon
In 58f7bd2a-ef82-4782-b4fb-db824f9c8...@googlegroups.com smilesonisa...@gmail.com writes: File aaa.py, line 5, in module from ccc.ddd import sss ImportError: No module named ccc.ddd directory structure as follows: ccc | ddd | aaa.py

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 11/12/2013 16:04, Chris Angelico wrote: I strongly believe that a career programmer should learn as many languages and styles as possible, but most of them can wait. I chuckle every time I read this one. Five

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 9:31:42 PM UTC+5:30, bob gailer wrote: On 12/11/2013 3:43 AM, Chris Angelico wrote: When you tell a story, it's important to engage the reader from the start...explain This is how to print Hello World to the console and worry about what exactly the console is

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 08:27:23 -0800, rusi wrote: [BTW: From the theoretical POV, imperative programming is 'unclean' because of assignment statements. From the practical POV of a teacher, the imperativeness of print is a bigger nuisance in students' thinking patterns ] +1 on this Trying to

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 3:27 AM, rusi rustompm...@gmail.com wrote: However when we have an REPL language like python, one has the choice of teaching the hello-world program as: print (Hello World) or just Hello World The second needs one more assumption than the first, viz that we are in

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Travis Griggs
On Dec 11, 2013, at 5:31 AM, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ My thoughts exactly! If you wade through

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Mark Lawrence
On 11/12/2013 17:19, Travis Griggs wrote: On Dec 11, 2013, at 5:31 AM, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Petite Abeille
On Dec 11, 2013, at 12:50 AM, Dan Stromberg drsali...@gmail.com wrote: Now the question becomes: Why did chardet tell me it was windows-1255? :) As it says on the tin: chardet guesses the encoding of text files. The operative word is ‘guesses’. --

Re: Script Request

2013-12-11 Thread Johannes Findeisen
Hi, On Wed, 11 Dec 2013 04:53:41 -0700 Jeff James wrote: Looking for a script which will check connectivity of any or all of our company URL's first thing in the morning to make sure none or our sites are down. Any suggestions ? Thank You This really is not a suggestion because the

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Ned Batchelder
On 12/10/13 6:50 PM, Dan Stromberg wrote: On Tue, Dec 10, 2013 at 1:07 PM, Petite Abeille petite.abei...@gmail.com mailto:petite.abei...@gmail.com wrote: On Dec 10, 2013, at 6:25 AM, Dan Stromberg drsali...@gmail.com mailto:drsali...@gmail.com wrote: The IMDB flat text file

adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread brian cleere
I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. #!/bin/env python import csv import sys if len(sys.argv) 3: print('Please specify a filename and column number: {} [csvfile] [column]'.format(sys.argv[0])) sys.exit(1)

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Tim Chase
On 2013-12-11 11:10, brian cleere wrote: filename = sys.argv[1] column = int(sys.argv[2]) for line in filename() , column (): elements = line.strip().split(',') values.append(int(elements[col])) 1) you need to open the file 2) you need to make use of the csv module on that file

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 6:10 AM, brian cleere briancle...@gmail.com wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. Your problem is akin to debugging an empty file :) It's not so much a matter of fixing what's not

Tracking the status of python script execution

2013-12-11 Thread Shyam Parimal Katti
Hello All, I am looking for a library that can help me trace the status of a live python script execution. i.e if I have a python script `x.py` with 200 lines, when I execute the script with `python x.py`, is there a way to trace the status of this execution in terms of number of lines executed

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Mark Lawrence
On 11/12/2013 19:10, brian cleere wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. #!/bin/env python import csv You never use the csv module. import sys if len(sys.argv) 3: print('Please specify a filename and

Re: Tracking the status of python script execution

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 6:26 AM, Shyam Parimal Katti spk...@nyu.edu wrote: I am looking for a library that can help me trace the status of a live python script execution. i.e if I have a python script `x.py` with 200 lines, when I execute the script with `python x.py`, is there a way to trace

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Mark Lawrence
On 11/12/2013 19:22, Chris Angelico wrote: On Thu, Dec 12, 2013 at 6:10 AM, brian cleere briancle...@gmail.com wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. Your problem is akin to debugging an empty file :) It's not

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 6:41 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: Square brackets in a usage description often mean optional. You may want to be careful of that. There's no really good solution though. There is, https://pypi.python.org/pypi/docopt/0.6.1 :) That appears to use x

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Mark Lawrence
On 11/12/2013 19:46, Chris Angelico wrote: On Thu, Dec 12, 2013 at 6:41 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: Square brackets in a usage description often mean optional. You may want to be careful of that. There's no really good solution though. There is,

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Chris Angelico
On Thu, Dec 12, 2013 at 7:00 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: I use the alternative X for a mandatory argument X. Also common, but how do you specify a keyword, then? Say you have a command with subcommands: $0 foo x y Move the foo to (x,y) $0 bar x y z Go to bar X, order a Y,

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Tim Delaney
On 12 December 2013 03:25, Chris Angelico ros...@gmail.com wrote: On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 11/12/2013 16:04, Chris Angelico wrote: I strongly believe that a career programmer should learn as many languages and styles as possible,

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Tim Chase
On 2013-12-12 07:03, Chris Angelico wrote: Also common, but how do you specify a keyword, then? Say you have a command with subcommands: $0 foo x y Move the foo to (x,y) $0 bar x y z Go to bar X, order a Y, and Z it [eg 'compress', 'gzip', 'drink'] How do you show that x/y/z are

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Mark Lawrence
On 11/12/2013 20:03, Chris Angelico wrote: On Thu, Dec 12, 2013 at 7:00 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: I use the alternative X for a mandatory argument X. Also common, but how do you specify a keyword, then? Say you have a command with subcommands: $0 foo x y Move the foo

Re: Figuring out what dependencies are needed

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 6:38 AM, Robert Kern robert.k...@gmail.com wrote: On 2013-12-11 13:27, Steven D'Aprano wrote: On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: Now I'd like to use the backtesting package from zipline (zipline.io), .io is not normally a file extension for Python files.

Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread Terry Reedy
On 12/11/2013 5:26 AM, Ben Finney wrote: Better design is to make the argument list a parameter to the ‘main’ function; this allows constructing an argument list specially for calling that function, without ‘main’ needing to know the difference. You'll also want to catch SystemExit and return

Re: Experiences/guidance on teaching Python as a first programming language

2013-12-11 Thread Ethan Furman
On 12/11/2013 12:34 AM, Devin Jeanpierre wrote: On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman et...@stoneleaf.us wrote: Doesn't sound like they do, as that's causing plenty of problems. In today's world that level of knowledge isn't always necessary, especially if your degree is not in CS.

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 10:35 AM, Ned Batchelder n...@nedbatchelder.comwrote: On 12/10/13 6:50 PM, Dan Stromberg wrote: Now the question becomes: Why did chardet tell me it was windows-1255? :) It probably told you it was Windows-1252 (I'm assuming the last 5 is a typo). Windows-1252 is a

[newbie] trying socket as a replacement for nc

2013-12-11 Thread Jean Dubois
I have an ethernet-rs232 adapter which allows me to connect to a measurement instrument by means of netcat on a linux system. e.g. entering nc 10.128.59.63 7000 allows me to enter e.g. *IDN? after which I get an identification string of the measurement instrument back. I thought I could

Re: Tracking the status of python script execution

2013-12-11 Thread Dan Stromberg
Long ago, I saw a C program that took another C program as input. It would output a copy of the original C program, interspersed with fprintf's that would display the text of the line current being executed. You might write something similar for Python, perhaps outputting the line being executed

Re: [newbie] trying socket as a replacement for nc

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandubois...@gmail.comwrote: I have an ethernet-rs232 adapter which allows me to connect to a measurement instrument by means of netcat on a linux system. e.g. entering nc 10.128.59.63 7000 allows me to enter e.g. *IDN? after which I get an

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 15:07:35 -0800, Dan Stromberg wrote: $ chardet mpaa-ratings-reasons.list mpaa-ratings-reasons.list: windows-1255 (confidence: 0.97) I'm aware that chardet is playing guessing games, though one would hope it would guess well most of the time, and give a reasonable

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 3:24 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 11 Dec 2013 15:07:35 -0800, Dan Stromberg wrote: $ chardet mpaa-ratings-reasons.list mpaa-ratings-reasons.list: windows-1255 (confidence: 0.97) I'm aware that chardet is playing

Re: [newbie] trying socket as a replacement for nc

2013-12-11 Thread Conor Hughes
Jean Dubois jeandubois...@gmail.com writes: I have an ethernet-rs232 adapter which allows me to connect to a measurement instrument by means of netcat on a linux system. e.g. entering nc 10.128.59.63 7000 allows me to enter e.g. *IDN? after which I get an identification string of the

Optimizing list processing

2013-12-11 Thread Steven D'Aprano
I have some code which produces a list from an iterable using at least one temporary list, using a Decorate-Sort-Undecorate idiom. The algorithm looks something like this (simplified): table = sorted([(x, i) for i,x in enumerate(iterable)]) table = [i for x,i in table] The problem here is that

Re: adding values from a csv column and getting the mean. beginner help

2013-12-11 Thread Christopher Welborn
On 12/11/2013 01:41 PM, Mark Lawrence wrote: On 11/12/2013 19:22, Chris Angelico wrote: There is, https://pypi.python.org/pypi/docopt/0.6.1 :) +1 for docopt. It makes everything very clear. Just type out your usage string, and then run docopt(usage_str) on it to get a dict of your args.

  1   2   3   >