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 w

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 P

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 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 > doesn't need t

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 wrote: > On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman 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

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 : > 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 string, rather than a literal

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ć 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 exception. It's pretty easy

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 unicode

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 from ccc.ddd import sss ImportEr

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:]: pri

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 : 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 at

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

2013-12-11 Thread Ben Finney
JL 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 being able to easily

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

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 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 -- https://mail.python.org/mailman/

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 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, wrote: > A few practical considerations, far away from theoretical > aspects. Mainly for non ascii, understand non native Englis

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 bel

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 uninformed-y

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 I

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 whi

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 wrote: > On Wed, Dec 11, 2013 at 7:34 PM, Devin Jeanpierre > 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, and filling in the important-but-le

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 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 round of applause

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 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 >> declaimed the following: > >>>That's like saying that when teaching woodwork we shouldn't let people >>>use hammers, we sh

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

Re: Script Request

2013-12-11 Thread Larry Martell
On Wed, Dec 11, 2013 at 6:53 AM, 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 import urllib sites = ["http://www.amazon.com/";, "

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 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 storytelli

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 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 any actual programs. They

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 followin

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__'" a

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 thi

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 -- ht

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 t

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'... >

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 l

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

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 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 > > impo

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

2013-12-11 Thread Roy Smith
In article , 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 > that makes it clearer what it's doing when use

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

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 woul

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 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 trie fit

Re: load_module for import entire package

2013-12-11 Thread Dave Angel
On Tue, 10 Dec 2013 23:28:31 -0800 (PST), Sergey 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, loaded for the

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

2013-12-11 Thread Grant Edwards
On 2013-12-11, Dennis Lee Bieber 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 verboten in my

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 t

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 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 sense to someone who'

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. I

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 defin

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 > Attr

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

2013-12-11 Thread Neil Cerutti
On 2013-12-11, Dennis Lee Bieber wrote: > On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing > 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 expect the students to complain about i

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 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 prefer define-be

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 variable/module

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 co

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 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 dependent on wei

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 and

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 La

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 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 fundamental difference

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 d

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 > > > > > from ccc.ddd import sss > > > > > ImportError: No module named ccc.ddd > > > > > directory structure as follows: > > > > > ccc > > > | > > > ddd > > >

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 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 years per l

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 co

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

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 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 the > R

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Travis Griggs
On Dec 11, 2013, at 5:31 AM, 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/ My thoughts exactly! If you wade through the comments ther

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 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! I

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Petite Abeille
On Dec 11, 2013, at 12:50 AM, Dan Stromberg 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’. -- https://mail.python.org/mailman/listinfo/python-list

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 s

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 mailto:petite.abei...@gmail.com>> wrote: On Dec 10, 2013, at 6:25 AM, Dan Stromberg mailto:drsali...@gmail.com>> wrote: > The IMDB flat text file probably came the closest, but it appears to

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) f

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 fi

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 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 working as of starting at

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 so

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 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 > the status

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 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 f

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 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 for a mandatory arg

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 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 :) T

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 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, and Z it [eg 'compress',

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 wrote: > On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence > 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 wa

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 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

Re: Figuring out what dependencies are needed

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 6:38 AM, Robert Kern 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. Are

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 t

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 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) nic

Re: Movie (MPAA) ratings and Python?

2013-12-11 Thread Dan Stromberg
On Wed, Dec 11, 2013 at 10:35 AM, Ned Batchelder wrote: > 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 super-set of IS

[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 accomplish

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 wrote: > 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

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 co

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 pla

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

2013-12-11 Thread Conor Hughes
Jean Dubois 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 measurement > instrument

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. When

  1   2   >