Usage of main()

2009-09-04 Thread Manuel Graune
Hello everyone, the standard structure of a python-program which is taught in all of the books I on python I read by now is simply something like: #!/usr/bin/python print Hello, world! ^D While reading about structuring a larger code-base, unit-testing, etc I stumbled on the idiom

Re: Usage of main()

2009-09-04 Thread Simon Brunning
2009/9/4 Manuel Graune manuel.gra...@koeln.de: How come the main()-idiom is not the standard way of writing a python-program (like e.g. in C)? Speaking for myself, it *is* the standard way to structure a script. I find it more readable, since I can put my main function at the very top where

Re: Usage of main()

2009-09-04 Thread alex23
Sean DiZazzo half.ital...@gmail.com wrote: What are you using to test the scripts?  I could be completely wrong, but I find it hard to believe that the second version is much (if any) faster than the first.  Then again, I don't know much about the internals... Sorry, Sean, unfortunately you

Re: Usage of main()

2009-09-04 Thread r
On Sep 4, 12:55 am, Manuel Graune manuel.gra...@koeln.de wrote: (snip) How come the main()-idiom is not the standard way of writing a python-program (like e.g. in C)? Why use a nested function when you already *in* main? thats like declaring variables when your compiler could just use some

Re: Usage of main()

2009-09-04 Thread Sean DiZazzo
On Sep 3, 10:55 pm, Manuel Graune manuel.gra...@koeln.de wrote: Hello everyone, the standard structure of a python-program which is taught in all of the books I on python I read by now is simply something like: #!/usr/bin/python print Hello, world! ^D While reading about structuring a

Re: Usage of main()

2009-09-04 Thread Sean DiZazzo
On Sep 3, 11:55 pm, alex23 wuwe...@gmail.com wrote: Sean DiZazzo half.ital...@gmail.com wrote: What are you using to test the scripts?  I could be completely wrong, but I find it hard to believe that the second version is much (if any) faster than the first.  Then again, I don't know much

Re: Usage of main()

2009-09-04 Thread Manuel Graune
Sean DiZazzo half.ital...@gmail.com writes: I'm trying to come up with an answer for you, but I can't... The if __name__ == __main__: idiom *is* the standard way to write python programs, but it's not there to speed up programs. It's there so that your program can be executed differently

Re: match braces?

2009-09-04 Thread lallous
Hello, Thank you all for your replies. A simple suggestion as Chris' actually might help. I am used to two spaces indentation since years, and apparently two spaces won't make it clear if no visuals were present (braces, or begin/end, ...) Though it is not comfortable to change a style, I will

Re: The future of Python immutability

2009-09-04 Thread r
The future of Python immutability Define future: The future is a time period commonly understood to contain all events that have yet to occur. It is the opposite of the past, and is the time after the present Define immutability: Not subject or susceptible to change. In object-oriented and

Re: Usage of main()

2009-09-04 Thread Carl Banks
On Sep 3, 11:55 pm, alex23 wuwe...@gmail.com wrote: Sean DiZazzo half.ital...@gmail.com wrote: What are you using to test the scripts?  I could be completely wrong, but I find it hard to believe that the second version is much (if any) faster than the first.  Then again, I don't know much

Re: possible attribute-oriented class

2009-09-04 Thread Peter Otten
Ken Newton wrote: class AttrClass(object): AttrClass lets you freely add attributes in nested manner def __init__(self): pass def __setitem__(self, key, value): return self.__dict__.__setitem__(key, value) def __repr__(self): return %s(%s) %

Re: Usage of main()

2009-09-04 Thread Carl Banks
On Sep 3, 11:39 pm, Simon Brunning si...@brunningonline.net wrote: 2009/9/4 Manuel Graune manuel.gra...@koeln.de: How come the main()-idiom is not the standard way of writing a python-program (like e.g. in C)? Speaking for myself, it *is* the standard way to structure a script. I find it

Re: The future of Python immutability

2009-09-04 Thread Francesco Bochicchio
On Sep 3, 9:07 pm, Nigel Rantor wig...@wiggly.org wrote: Right, this is where I would love to have had more experience with Haksell. Yes, as soon as you get to a situation where no thread can access shared state that is mutable your problems go away, you're also getting no work done becasue

Re: The future of Python immutability

2009-09-04 Thread Ulrich Eckhardt
Nigel Rantor wrote: John Nagle wrote: Immutability is interesting for threaded programs, because immutable objects can be shared without risk. Consider a programming model where objects shared between threads must be either immutable or synchronized in the sense that Java uses the term.

Re: The future of Python immutability

2009-09-04 Thread Paul Rubin
Ulrich Eckhardt eckha...@satorlaser.com writes: Lastly, for the message passing, you also need shared, mutable structures (queues), so you can't live completely without conventional locking. But that can be completely behind the scenes in the language or library implementation. The application

cross platform distribution

2009-09-04 Thread vpr
Hi All After a couple of experiments, searching around and reading Steve Holden's lament about bundling and ship python code, I thought I'd direct this to to the group. I'm using Python 2.6 btw. I've build a commercial application that I'd like to bundle and ship. I'd like to protect some of my

Re: match braces?

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 00:25:34 -0700, lallous wrote: Hello, Thank you all for your replies. A simple suggestion as Chris' actually might help. I am used to two spaces indentation since years, and apparently two spaces won't make it clear if no visuals were present (braces, or begin/end,

Re: python module for data comparison of 2 MySQL servers

2009-09-04 Thread Kushal Kumaran
On Wed, Sep 2, 2009 at 5:30 AM, wrote: I have 2 MySQL servers in 2 different data centers. Between them, there is data replication setup. Is there a python tool so I can do data comparison for daily records? Basically, just access both servers and do a diff in memory and print out records.

Re: obscure problem using elementtree to make xhtml website

2009-09-04 Thread Richard Brodie
Stefan Behnel stefan...@behnel.de wrote in message news:4aa01462$0$31340$9b4e6...@newsspool4.arcor-online.net... Not a bug in IE (this time), which is correctly parsing the file as html. ... which is obviously not the correct thing to do when it's XHTML. It isn't though; it's HTML with a

Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?

2009-09-04 Thread The Music Guy
I have a peculiar problem that involves multiple inheritance and method calling. I have a bunch of classes, one of which is called MyMixin and doesn't inherit from anything. MyMixin expects that it will be inherited along with one of several other classes that each define certain functionality.

Re: Usage of main()

2009-09-04 Thread Jan Kaliszewski
So yes, depending on the nature of your code, its quite conceivable to find distinct performance differences between code using the __main__ idiom and code without. But -- it should be emphasized -- it's faster thanks to running code (an doing name lookups) within a function, and *not* thanks

Re: Why does this group have so much spam?

2009-09-04 Thread BJ Swope
And I would kindly appreciate it if you fellas wouldn't go solving this little spam problem! Selling Anti-Spam industry leading appliances has managed to put me in a rather nice house and I'd hate to lose it just because you fellas went and solved the problem! ;) On Thu, Sep 3, 2009 at 11:24

Re: Usage of main()

2009-09-04 Thread Jan Kaliszewski
04-09-2009 o 08:37:43 r rt8...@gmail.com wrote: Why use a nested function when you already *in* main? I understand you name global scope as 'main'. But (independently of using the __main__ idiom and so on) it is still good idea not to place to much code in the global scope but to place your

Re: The future of Python immutability

2009-09-04 Thread Hendrik van Rooyen
On Thursday 03 September 2009 21:07:21 Nigel Rantor wrote: That is not the challenge, that's the easy part. The challenge is getting useful information out of a system that has only been fed immutable objects. Is it really that difficult? (completely speculative): class MyAnswer(object):

Re: python module for data comparison of 2 MySQL servers

2009-09-04 Thread Tino Wildenhain
Hi, Am 02.09.2009 02:00, schrieb none: I have 2 MySQL servers in 2 different data centers. Between them, there is data replication setup. Is there a python tool so I can do data comparison for daily records? Why should the data differ and the replication not detect and correct it? I

Re: obscure problem using elementtree to make xhtml website

2009-09-04 Thread Stefan Behnel
Richard Brodie wrote: Stefan Behnel wrote: Lee wrote: Not a bug in IE (this time), which is correctly parsing the file as html. ... which is obviously not the correct thing to do when it's XHTML. It isn't though; it's HTML with a XHTML DOCTYPE Not the page I look at (i.e. the link provided

logger module : Question about log message format

2009-09-04 Thread jorma kala
Hi, I've created a logger like this: LOG_FILENAME = 'test.txt' fh=logging.FileHandler(LOG_FILENAME,'w') logger1 = logging.getLogger('myLogger1') logger1.addHandler(fh) logger1.setLevel(logging.INFO) logger1.info('message from logger1') and was hoping to get log messages in this format in my log

Re: Usage of main()

2009-09-04 Thread Mel
Manuel Graune wrote: [ ... ] thanks for your answer. What you are explaining is exactly why I tried it in the first place. I'm just wondering why (this is my impression, not necessaryly the reallity) none of the recommended texts on python put this in the first chapters. Instead - if it is

Invitation to connect on LinkedIn

2009-09-04 Thread Navneet Khanna
LinkedIn Navneet Khanna requested to add you as a connection on LinkedIn: -- Jaime, I'd like to add you to my professional network on LinkedIn. - Navneet Accept invitation from Navneet Khanna

Python SSH interface

2009-09-04 Thread Mag Gam
Is there something similar to NetSSH (http://search.cpan.org/dist/Net-SSH-Perl/) for python? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python SSH interface

2009-09-04 Thread Avell Diroll
Mag Gam wrote: Is there something similar to NetSSH (http://search.cpan.org/dist/Net-SSH-Perl/) for python? I don't know much about perl modules functionalities, but paramiko might be what you are searching for. http://www.lag.net/paramiko/ Cheers Ju -- Those who do not understand Unix

Re: Python SSH interface

2009-09-04 Thread Diez B. Roggisch
Mag Gam wrote: Is there something similar to NetSSH (http://search.cpan.org/dist/Net-SSH-Perl/) for python? Google dead today? From the 3.000.000 answers for python + ssh, I suggest paramiko, but there are more options. Diez -- http://mail.python.org/mailman/listinfo/python-list

File Handling Problem

2009-09-04 Thread joy99
Dear Group, I have a file. The file has multiple lines. I want to get the line number of any one of the strings. Once I get that I like to increment the line number and see the string of the immediate next line or any following line as output. The problem as I see is nicely handled in list, like

Re: recursive decorator

2009-09-04 Thread Michele Simionato
On Sep 3, 6:41 pm, Ethan Furman et...@stoneleaf.us wrote: The original thread by Bearophile:    http://mail.python.org/pipermail/python-list/2009-May/711848.html I have read the thread. What Bearophile wants can be implemented with a bytecode hack, no need for the decorator module. Let me call

Re: Usage of main()

2009-09-04 Thread Ben Finney
Jan Kaliszewski z...@chopin.edu.pl writes: I understand you name global scope as 'main'. But (independently of using the __main__ idiom and so on) it is still good idea not to place to much code in the global scope but to place your app-logic code in functions -- because, as we noted: * in

Re: possible attribute-oriented class

2009-09-04 Thread Jan Kaliszewski
[originally from python-list@python.org, crossposted to python-id...@python.org] 04-09-2009 o 00:46:01 Ken Newton krnew...@gmail.com wrote: I have created the following class definition with the idea of making a clean syntax for non-programmers to created structured data within a python

Re: cross platform distribution

2009-09-04 Thread Philip Semanchuk
On Sep 4, 2009, at 4:44 AM, vpr wrote: Hi All After a couple of experiments, searching around and reading Steve Holden's lament about bundling and ship python code, I thought I'd direct this to to the group. I'm using Python 2.6 btw. I've build a commercial application that I'd like to

Re: The future of Python immutability

2009-09-04 Thread Adam Skutt
On Sep 3, 2:03 pm, John Nagle na...@animats.com wrote:      Suppose, for discussion purposes, we had general immutable objects. Objects inherited from immutableobject instead of object would be unchangeable once __init__ had returned.  Where does this take us? You can create this in various

Re: python daemon - compress data and load data into MySQL by pyodbc

2009-09-04 Thread MacRules
Dennis Lee Bieber wrote: On Thu, 03 Sep 2009 14:43:40 -0400, MacRules macru...@nome.com declaimed the following in gmane.comp.python.general: Oracle DB in data center 1 (LA, west coast) MSSQL DB in data center 2 (DC, east coast) Note that your thread subject line states MySQL...

How to access ODBC databases ?

2009-09-04 Thread Timothy Madden
Hello I would like to use a database through ODCB in my python application. I have Slackware Linux, but I would not mind a portable solution, since python runs on both Unixes and Windows. I would like a free/open-source solution and the python module for ODBC access that I have found is

Re: File Handling Problem

2009-09-04 Thread Lucas Prado Melo
On Fri, Sep 4, 2009 at 9:50 AM, joy99 subhakolkata1...@gmail.com wrote: Dear Group, I have a file. The file has multiple lines. I want to get the line number of any one of the strings. Once I get that I like to increment the line number and see the string of the immediate next line or any

Re: possible attribute-oriented class

2009-09-04 Thread Colin J. Williams
Jan Kaliszewski wrote: [originally from python-list@python.org, crossposted to python-id...@python.org] 04-09-2009 o 00:46:01 Ken Newton krnew...@gmail.com wrote: I have created the following class definition with the idea of making a clean syntax for non-programmers to created structured

Re: The future of Python immutability

2009-09-04 Thread Scott David Daniels
John Nagle wrote: ... Suppose, for discussion purposes, we had general immutable objects. Objects inherited from immutableobject instead of object would be unchangeable once __init__ had returned. Where does this take us? Traditionally in Python we make that, once __new__ had returned.

Re: What python can NOT do?

2009-09-04 Thread Mike Coleman
On Aug 28, 5:37 pm, qwe rty hkh00...@gmail.com wrote: i know that an interpreted language like python can't be used to make an operating system or system drivers. what else can NOT be done in python? what are the limitations of the language? Neither of those is strictly true. It is true,

Re: possible attribute-oriented class

2009-09-04 Thread Scott David Daniels
Ken Newton wrote: ... I would appreciate comments on this code. First, is something like this already done? Second, are there reasons for not doing this? ... class AttrClass(object): ... def __repr__(self): return %s(%s) % (self.__class__.__name__, self.__dict__.__repr__())

Re: File Handling Problem

2009-09-04 Thread Rami Chowdhury
f = open(myfile.txt, r) list_one = f.read().splitlines() f.close() Or use f.readlines(), which would do the same thing IIRC? On Fri, 04 Sep 2009 07:46:42 -0700, Stephen Fairchild someb...@somewhere.com wrote: joy99 wrote: Dear Group, I have a file. The file has multiple lines. I want

Running Sum script

2009-09-04 Thread Jul
hello, I have a .txt file that is in this format -- 12625 17000 12000 14500 17000 12000 17000 14500 14500 12000 ...and so on... i need to create a python script that will open this file and have a running sum until the end of file. it sounds really simple its just for some reason i am having

Re: Support for Windows 7 ?

2009-09-04 Thread Martin v. Löwis
On of my students has installed Windows 7 RTM on his cherished computer, and claims that Python 2.6.2 doesn't support it. The sample program had a problem with the library function os.listdir(dirarg) always returning the same result for different values of dirarg. DO YOU KNOW HOW FAR

Re: Running Sum script

2009-09-04 Thread David Smith
Jul wrote: hello, I have a .txt file that is in this format -- 12625 17000 12000 14500 17000 12000 17000 14500 14500 12000 ...and so on... i need to create a python script that will open this file and have a running sum until the end of file. it sounds really simple its

Re: Support for Windows 7 ?

2009-09-04 Thread Pascale Mourier
Martin v. Löwis a écrit : If there is a specific problem, we would need a specific test case, to be reported to bugs.python.org. Tks for the name above. I asked my student to prepare the bug demo package, but I didn't know how to send it! Given that the problem is with reading the file

Re: Running Sum script

2009-09-04 Thread Stephen Fairchild
Jul wrote: hello, I have a .txt file that is in this format -- 12625 17000 12000 14500 17000 12000 17000 14500 14500 12000 ...and so on... i need to create a python script that will open this file and have a running sum until the end of file. Untested: with

Re: Support for Windows 7 ?

2009-09-04 Thread Martin v. Löwis
Given that the problem is with reading the file system, it is likely to be w/ sth else than Windows 7, maybe some weird HD partition combination? Without having seen any details, I refuse to guess. Most likely, it is a user mistake. Regards, Martin --

Re: Running Sum script

2009-09-04 Thread Jul
On Sep 4, 2:21 pm, Stephen Fairchild someb...@somewhere.com wrote: Jul wrote: hello, I have a .txt file that is in this format -- 12625 17000 12000 14500 17000 12000 17000 14500 14500 12000 ...and so on... i need to create a python script that will open this file

Application-global switches?

2009-09-04 Thread kj
I'm looking for the best-practice way to define application-global read-only switches, settable from the command line. The best example I can think of of such global switch is the built-in variable __debug__. This variable is visible everywhere in a program, and broadly affects its operation.

Re: Running Sum script

2009-09-04 Thread David Smith
Jul wrote: On Sep 4, 2:21 pm, Stephen Fairchild someb...@somewhere.com wrote: Jul wrote: hello, I have a .txt file that is in this format -- 12625 17000 12000 14500 17000 12000 17000 14500 14500 12000 ...and so on... i need to create a python script that will open this file and

Re: Application-global switches?

2009-09-04 Thread Terry Reedy
kj wrote: I'm looking for the best-practice way to define application-global read-only switches, settable from the command line. The best example I can think of of such global switch is the built-in variable __debug__. This variable is visible everywhere in a program, and broadly affects its

Re: Running Sum script

2009-09-04 Thread Rami Chowdhury
Could you let us know what kind of error you are getting? I don't know if this is your error, but this line won't run: readData = formisanoOpen.readLines() Since Python is case-sensitive, you would need a lower-case 'l' in 'readlines()' -- perhaps that would solve your problem? On Fri,

Re: Application-global switches?

2009-09-04 Thread ici
On Sep 4, 9:29 pm, kj no.em...@please.post wrote: I'm looking for the best-practice way to define application-global read-only switches, settable from the command line.  The best example I can think of of such global switch is the built-in variable __debug__.  This variable is visible

Re: How to access ODBC databases ?

2009-09-04 Thread Timothy Madden
Martin P. Hellwig wrote: Timothy Madden wrote: cut conn = pyodbc.connect('DRIVER={PostgreSQL Unicode};Servername=127.0.0.1;UID=pikantBlue;Database=pikantBlue') Traceback (most recent call last): File stdin, line 1, in module pyodbc.Error: ('0', '[0] [nxDC (202) (SQLDriverConnectW)')

Re: Running Sum script

2009-09-04 Thread Juli Dolzhenko
On Sep 4, 2:52 pm, Rami Chowdhury rami.chowdh...@gmail.com wrote: Could you let us know what kind of error you are getting? I don't know if this is your error, but this line won't run: readData = formisanoOpen.readLines() Since Python is case-sensitive, you would need a lower-case 'l' in

Re: cross platform distribution

2009-09-04 Thread vpr
On Sep 4, 3:33 pm, Philip Semanchuk phi...@semanchuk.com wrote: On Sep 4, 2009, at 9:24 AM, vpr wrote: On Sep 4, 3:19 pm, Philip Semanchuk phi...@semanchuk.com wrote: On Sep 4, 2009, at 4:44 AM, vpr wrote: Hi All After a couple of experiments, searching around and reading Steve

Re: cross platform distribution

2009-09-04 Thread ianaré
These are all good suggestions. I just wanted to add that you can distribute pre-built Linux packages for the most popular distros like one for RHEL/Centos/Fedora as RPM and one for Debian/Ubuntu as DEB. Any C code in them would be compiled. On Sep 4, 9:33 am, Philip Semanchuk

Re: possible attribute-oriented class

2009-09-04 Thread Jan Kaliszewski
04-09-2009 Ken Newton krnew...@gmail.com wrote: I like this version very much. I'm ready to put this into practice to see how it works in practice. [snip] Not only you (Ken) and me. :-) It appears that the idea is quite old. Nick Coghlan replied at python-id...@python.org: Jan Kaliszewski

Re: Running Sum script

2009-09-04 Thread Tobiah
in the terminal i get a very strange permission denied error that might not have anything to do with the code. I checked permissions for the file and they are set to read and write so, again, I am really not sure what going wrong. Try: python myfile Or chmod +x myfile

Re: Running Sum script

2009-09-04 Thread Maggie
On Sep 4, 4:37 pm, Tobiah t...@tobiah.org wrote: in the terminal i get a very strange permission denied error that might not have anything to do with the code. I checked permissions for the file and they are set to read and write so, again, I am really not sure what going wrong. Try:

Re: Application-global switches?

2009-09-04 Thread Ethan Furman
ici wrote: On Sep 4, 9:29 pm, kj no.em...@please.post wrote: I'm looking for the best-practice way to define application-global read-only switches, settable from the command line. The best example I can think of of such global switch is the built-in variable __debug__. This variable is

Re: Running Sum script

2009-09-04 Thread Rami Chowdhury
try it where? code or terminal? Please try these in the terminal -- the permission denied error may be due to your shell not being able to execute the Python script, instead of your Python script not being able to open the data file. On Fri, 04 Sep 2009 13:37:10 -0700, Maggie

Re: How to access ODBC databases ?

2009-09-04 Thread Martin P. Hellwig
Timothy Madden wrote: Martin P. Hellwig wrote: Timothy Madden wrote: cut conn = pyodbc.connect('DRIVER={PostgreSQL Unicode};Servername=127.0.0.1;UID=pikantBlue;Database=pikantBlue') Traceback (most recent call last): File stdin, line 1, in module pyodbc.Error: ('0', '[0] [nxDC (202)

Re: Running Sum script

2009-09-04 Thread
On Sep 4, 4:37 pm, Maggie la.f...@gmail.com wrote: On Sep 4, 4:37 pm, Tobiah t...@tobiah.org wrote: in the terminal i get a very strange permission denied error that might not have anything to do with the code. I checked permissions for the file and they are set to read and write so,

Re: Support for Windows 7 ?

2009-09-04 Thread Martin P. Hellwig
Michel Claveau - MVP wrote: cut Du coup, j'ai envie de déduire : - Que certains étudiants d'écoles de commerce françaises préfèrent travailler avec l'étranger plutôt qu'avec le français. - Il faudra dire à d'autres étudiants d'écoles de commerce françaises que le fait de ne pas

Re: Problem w/ mysqldump

2009-09-04 Thread Victor Subervi
I got essentially the same printout. There were the following, among many others: mysqldump.exe mysqldump.pdb What's a *.pdb file? Don't know it matters. If there were just some darn way to know where that daggone database is, I could copy it and move it to another machine. TIA, V On Thu, Sep 3,

Re: [Python-ideas] possible attribute-oriented class

2009-09-04 Thread George Sakkis
On Fri, Sep 4, 2009 at 4:37 PM, Jan Kaliszewskiz...@chopin.edu.pl wrote: 04-09-2009 Ken Newton krnew...@gmail.com wrote: I like this version very much. I'm ready to put this into practice to see how it works in practice. [snip] Not only you (Ken) and me. :-) It appears that the idea is

Re: Running Sum script

2009-09-04 Thread Chris Rebert
On Fri, Sep 4, 2009 at 1:49 PM, juli.dolzhe...@gmail.com wrote: On Sep 4, 4:37 pm, Maggie la.f...@gmail.com wrote: On Sep 4, 4:37 pm, Tobiah t...@tobiah.org wrote: in the terminal i get a very strange permission denied error that might not have anything to do with the code. I checked

Re: obscure problem using elementtree to make xhtml website

2009-09-04 Thread Nobody
On Fri, 04 Sep 2009 13:21:54 +0200, Stefan Behnel wrote: Not a bug in IE (this time), which is correctly parsing the file as html. ... which is obviously not the correct thing to do when it's XHTML. It isn't though; it's HTML with a XHTML DOCTYPE Not the page I look at (i.e. the link

Re: Subclassing list and splicing

2009-09-04 Thread Nobody
On Thu, 03 Sep 2009 17:10:12 +, Kreso wrote: I would prefer that resulting object m belonged to myclist class. How to obtain such behaviour? Must I somehow implement __getslice__ method myself? Yes; you should also implement __getitem__(), as this is used for extended slices. --

Compiler.ast helper function literal_eval in python 2.4

2009-09-04 Thread Sean Talts
Hi, I'm trying to parse some python with the compiler module, select a subset of the AST returned, and then evaluate that subset, all in python 2.4. It seems like in python 2.6 the compiler.ast.literal_eval function may be what I'm looking for, but unfortunately for my project we are restricted

How to download directly to a file?

2009-09-04 Thread kj
I want to send a POST request and have the returned content put directly into a file. Is there a way to do this easily in Python? I've been looking at the documentation for urllib2, but I can't see a direct way to do this, other than saving the returned contents to an in-memory variable and

Re: How to download directly to a file?

2009-09-04 Thread Diez B. Roggisch
kj schrieb: I want to send a POST request and have the returned content put directly into a file. Is there a way to do this easily in Python? I've been looking at the documentation for urllib2, but I can't see a direct way to do this, other than saving the returned contents to an in-memory

incorrect DeprecationWarning?

2009-09-04 Thread Alan G Isaac
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. class MyError(Exception): ... def __init__(self, message): ... Exception.__init__(self) ... self.message = message ... e =

Problems with hex-conversion functions

2009-09-04 Thread Arnon Yaari
Hello everyone. Perhaps I'm missing something, but I see several problems with the two hex-conversion function pairs that Python offers: 1. binascii.hexlify and binascii.unhexlify 2. bytes.fromhex and bytes.hex Problem #1: bytes.hex is not implemented, although it was specified in PEP 358. This

Re: incorrect DeprecationWarning?

2009-09-04 Thread Terry Reedy
Alan G Isaac wrote: Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. class MyError(Exception): ... def __init__(self, message): ... Exception.__init__(self) ... self.message

Re: setting Referer for urllib.urlretrieve

2009-09-04 Thread E
On Aug 10, 10:21 am, samwyse samw...@gmail.com wrote: On Aug 9, 9:41 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sun, 09 Aug 2009 06:13:38 -0700,samwysewrote: Here's what I have so far: import urllib class AppURLopener(urllib.FancyURLopener):     version

Re: How to download directly to a file?

2009-09-04 Thread kj
In 7gdgslf2ogf8...@mid.uni-berlin.de Diez B. Roggisch de...@nospam.web.de writes: kj schrieb: I want to send a POST request and have the returned content put directly into a file. Is there a way to do this easily in Python? I've been looking at the documentation for urllib2, but I can't see

global variable not working inside function. Increment

2009-09-04 Thread Helvin
Hi, This increment thing is driving me nearly to the nuts-stage. I have a function that allows me to pick points. I want to count the number of times I have picked points. global no_picked no_picked = 0 def picked(object, event): no_picked += 1 print no_picked

Re: global variable not working inside function. Increment

2009-09-04 Thread Rami Chowdhury
global no_picked no_picked = 0 def picked(object, event): no_picked += 1 print no_picked In order to be able to affect variables in the global scope, you need to declare them global inside the function, and not at the global scope. So your code should read:

Re: global variable not working inside function. Increment

2009-09-04 Thread Helvin Lui
Wow!!! Thanks a million!! It worked! = DThanks for the fast reply too! Helvin On Sat, Sep 5, 2009 at 11:52 AM, Rami Chowdhury rami.chowdh...@gmail.comwrote: global no_picked no_picked = 0 def picked(object, event): no_picked += 1 print no_picked In order to

Re: Annoying octal notation

2009-09-04 Thread NevilleDNZ
On Sep 3, 2:57 pm, James Harris james.harri...@googlemail.com wrote: On 3 Sep, 14:26, Albert van der Horst alb...@spenarnc.xs4all.nl wrote: In article 6031ba08-08c8-416b-91db-ce8ff57ae...@w6g2000yqw.googlegroups.com, James Harris  james.harri...@googlemail.com wrote: SNIP So you are

Re: The future of Python immutability

2009-09-04 Thread sturlamolden
On 4 Sep, 06:20, John Nagle na...@animats.com wrote: In the current CPython implementation, every object has a reference count, even immutable ones. This must be a writable field - and here you have your race condition, even for immutable objects.     That's an implementation problem with

Two schools in Argentina provide model for Jewish education

2009-09-04 Thread bilawal samoon
BUENOS AIRES, Argentina (JTA) -- The old Citroen on the campus of one of ORT’s two schools in Buenos Aires sits stripped to a skeleton, its doors removed, dangling wires spilling out of the dashboard. For more details www.technicaledu.blogspot.com --

Re: The future of Python immutability

2009-09-04 Thread sturlamolden
On 3 Sep, 20:03, John Nagle na...@animats.com wrote:      Python doesn't have immutable objects as a general concept, but it may be headed in that direction.  There was some fooling around with an immmutability API associated with NumPy back in 2007, but that was removed.  As more immutable

Re: pexpect and unicode strings

2009-09-04 Thread Sean DiZazzo
On Sep 4, 7:11 pm, Mathew Oakes mathew.oa...@memechine.org wrote: Is there anything that can be done to make pexpect spawns send unicode lines? In this example they are just middot characters, but this process needs to be able to handle languages in other character sets. spokentext =

pexpect and unicode strings

2009-09-04 Thread Mathew Oakes
Is there anything that can be done to make pexpect spawns send unicode lines? In this example they are just middot characters, but this process needs to be able to handle languages in other character sets. spokentext = u'Nation . Search the FOX Nation . czars \xb7 Health care \xb7 town

SEI Job Opening

2009-09-04 Thread bilawal samoon
SEI is seeking a FT, YR Photovoltaic Technical Manager. If you are a team player with a minimum of 4 years PV installation, curriculum and education development, management experience, the ability to multitask, strong verbal and written communication skills, and a sense of humor, SEI invites you

Re: The future of Python immutability

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 19:23:06 -0700, sturlamolden wrote: I one did a test of NumPy's mutable arrays against Matlab's immutable arrays on D4 wavelet transforms. On an array of 64 MB of double precision floats, the Python/NumPy version was faster by an order of magnitude. Is the difference

Re: What python can NOT do?

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 08:21:15 -0700, Mike Coleman wrote: It is true, though, that Python cannot be used to write arbitrarily complex one-liners, though. Incorrect. exec x=1\0while x 5:\0 x+=1\0print x.replace('\0','\n') 5 Take (almost) any arbitrary piece of Python code. Replace all

Re: How to download directly to a file?

2009-09-04 Thread Chris Rebert
On Fri, Sep 4, 2009 at 4:35 PM, kjno.em...@please.post wrote: In 7gdgslf2ogf8...@mid.uni-berlin.de Diez B. Roggisch de...@nospam.web.de writes: kj schrieb: I want to send a POST request and have the returned content put directly into a file.  Is there a way to do this easily in Python? I've

Re: What python can NOT do?

2009-09-04 Thread Grant Edwards
On 2009-09-05, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Fri, 04 Sep 2009 08:21:15 -0700, Mike Coleman wrote: It is true, though, that Python cannot be used to write arbitrarily complex one-liners, though. Incorrect. exec x=1\0while x 5:\0 x+=1\0print

Re: The future of Python immutability

2009-09-04 Thread sturlamolden
On 5 Sep, 05:12, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: Is the difference because of mutability versus immutability, or because of C code in Numpy versus Matlab code? Are you comparing bananas and pears? It consisted of something like this import numpy def

Re: The future of Python immutability

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 06:36:59 -0700, Adam Skutt wrote: Nope, preventing mutation of the objects themselves is not enough. You also have to forbid variables from being rebound (pointed at another object). Consider this simple example: -- Thread 1 -- | -- Thread 2

Re: recursive decorator

2009-09-04 Thread Michele Simionato
On Sep 4, 7:03 pm, Ethan Furman et...@stoneleaf.us wrote: Just to verify, using the decorator module is portable, yes? Yes, it is portable. BTW, here is what you want to do (requires decorator-3.1.2): from decorator import FunctionMaker def bindfunc(f): name = f.__name__ signature =

  1   2   >