file extension while saving Python files
Team, In Python IDE, while we save the script, it will prompt the save Dialog. If we specify the filename as "Test". Then file will be saved without extension as "Test" and not "Test.py". Is it possible to save the script with .py extension automatically (as Test.py)? Thanks, vairamuthu. -- http://mail.python.org/mailman/listinfo/python-list
Re: file extension while saving Python files
On 2011-11-08 11:05, vaira muthu wrote: In Python IDE, ... Which Python IDE? There are dozens: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On 07.11.2011 23:06, Chris Angelico wrote: > On Tue, Nov 8, 2011 at 8:46 AM, david vierra wrote: >> But, you didn't write an all() function. You wrote a more specialized >> allBoolean() function. I think this comparison is more fair to the >> builtin all(): > > So really, it's not "all() is slow" but "function calls are slow". > Maybe it'd be worthwhile making an all-factory: PLEASE say you're joking. If I saw code like that on any of our project, this would definitely qualify for a DailyWTF. Regards, Henrik -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On Tue, Nov 8, 2011 at 11:09 PM, Henrik Faber wrote: > On 07.11.2011 23:06, Chris Angelico wrote: >> So really, it's not "all() is slow" but "function calls are slow". >> Maybe it'd be worthwhile making an all-factory: > > PLEASE say you're joking. If I saw code like that on any of our project, > this would definitely qualify for a DailyWTF. For the benefit of anyone who was actually in doubt: YES, I was joking. Do *not* put code like this into any production project. But it's still fun to write bad code once in a while. It's like Mythbusters getting to crash cars. Fun partly _because_ it's something you normally don't want to do. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python ORMs Supporting POPOs and Substituting Layers in Django
On 11/08/2011 02:35 AM, Chris Angelico wrote: On Tue, Nov 8, 2011 at 4:09 PM, Lie Ryan wrote: I much prefer the "everything's an object" notion. C's array literals are just as weird (although in C, you can directly dereference a literal character array - "ABCDEFG"[note_idx] will give you a note name as a char) Hey, in C you can also do note_idx["ABCDEFG"] and get the selected character as if you had written what you showed. Plenty of opportunity in C to write illegible code. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes accessing functions with double pointers
Thank you Chris :-) On Mon, Nov 7, 2011 at 11:29 PM, Chris Rebert wrote: > On Mon, Nov 7, 2011 at 2:06 PM, Eleftherios Garyfallidis > wrote: > > Hello, > > > > Is it possible using ctypes to call C functions from a shared object > > containing double pointers e.g. int foo(float **i) and if yes how? > > (Untested conjecture:) > > import ctypes > # ...create ctypes_wrapped_foo... > the_float = ctypes.c_float(42.1) > float_ptr = ctypes.byref(the_float) > i = ctypes.byref(float_ptr) > result_integer = ctypes_wrapped_foo(i) > > Cheers, > Chris > -- http://mail.python.org/mailman/listinfo/python-list
Help catching error message
What I say is this: def SaveEvents(self,events): try: plistlib.writePlist(events, self.path+'/Data/Events.plist') # None if OK except IOError: return "IOError: [Errno 13] Apache can't write Events.plist file" Note that success returns"None" while failure returns a string. I catch the error like this: errorStatus=Data.Dict.SaveEvents(Data.Plist.Events) if errorStatus: content=errorStatus It works, but isn there a more elegant way to do it? As in, one line? I can imagine if success returned nothing then content would remain unchanged. Isn't there a built-in way to send an error string back and then catch it as a variable name? This is Py3 inside WSGI. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list
Re: file extension while saving Python files
In vaira muthu writes: > Team, > In Python IDE, while we save the script, it will prompt the save > Dialog. If we specify the filename as "Test". Then file will be saved > without extension as "Test" and not "Test.py". Is there a drop-down list selection for specifying the file type? -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" -- http://mail.python.org/mailman/listinfo/python-list
Re: file extension while saving Python files
if it is not a python ide then, you have to explicitly specify the extension. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help catching error message
Gnarlodious wrote: What I say is this: def SaveEvents(self,events): try: plistlib.writePlist(events, self.path+'/Data/Events.plist') # None if OK except IOError: return "IOError: [Errno 13] Apache can't write Events.plist file" Note that success returns"None" while failure returns a string. I catch the error like this: errorStatus=Data.Dict.SaveEvents(Data.Plist.Events) if errorStatus: content=errorStatus It works, but isn there a more elegant way to do it? As in, one line? I can imagine if success returned nothing then content would remain unchanged. Isn't there a built-in way to send an error string back and then catch it as a variable name? This is Py3 inside WSGI. -- Gnarlie Hi, There's no need to rephrase an exception unless you want to *add* information. def saveEvents(self,events): plistlib.writePlist(events, self.path+'/Data/Events.plist') try: Data.Dict.SaveEvents(Data.Plist.Events) except IOError, exc: # i'm using python 2.5, this except clause may have changed in py3 content = str(exc) JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Help catching error message
Jean-Michel Pichavant wrote: Gnarlodious wrote: What I say is this: def SaveEvents(self,events): try: plistlib.writePlist(events, self.path+'/Data/Events.plist') # None if OK except IOError: return "IOError: [Errno 13] Apache can't write Events.plist file" Note that success returns"None" while failure returns a string. I catch the error like this: errorStatus=Data.Dict.SaveEvents(Data.Plist.Events) if errorStatus: content=errorStatus It works, but isn there a more elegant way to do it? As in, one line? I can imagine if success returned nothing then content would remain unchanged. Isn't there a built-in way to send an error string back and then catch it as a variable name? This is Py3 inside WSGI. -- Gnarlie Hi, There's no need to rephrase an exception unless you want to *add* information. def saveEvents(self,events): plistlib.writePlist(events, self.path+'/Data/Events.plist') try: Data.Dict.SaveEvents(Data.Plist.Events) except IOError, exc: # i'm using python 2.5, this except clause may have changed in py3 content = str(exc) JM looks like for whatever reason the formating has gone crazy. http://www.copypastecode.com/100088/ jm -- http://mail.python.org/mailman/listinfo/python-list
Re: file extension while saving Python files
In article , vaira muthu wrote: > In Python IDE, while we save the script, it will prompt the save > Dialog. If we specify the filename as "Test". Then file will be saved > without extension as "Test" and not "Test.py". > > Is it possible to save the script with .py extension automatically (as > Test.py)? If the IDE you are referring to is IDLE, there is an issue recently opened that requests this change: http://bugs.python.org/issue10364 -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: easy_install doesn't install non-package *.py file
On 11/7/2011 11:32 PM, Makoto Kuwata wrote: I got trouble about easy_install command. My package: README.rst setup.py foobar/ foobar/__init__.py foobar/data/ foobar/data/template.py In the above example, 'foobar/data/template.py' is just a template data file (= not a python module file). Then why is it .py? If it is just data, use .txt. If .py, it should be python code run either directly or imported, though I suppose you could exec it. (I have no idea how renaming would affect your problem.) (notice that 'foobar/data/__init__.py' doesn't exist.) I did, and no, I do not know the answer to your question. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Line continuation issue\
On Fri, Nov 04, 2011 at 11:10:58AM -0400, Steven Lehar wrote: > Is this the right place to propose language extensions? > > My Python code keeps expanding rightwards, it is difficult to keep it > contained within reasonable limits. But the standard line continuation \ > is positively anti-Pythonic because an *invisible* white space between \ > and [CR] will render it useless. > > How about a new Python symbol, maybe \\ that CAN have following whitespace > which is ignored, so that seeing a \\ in the code forces it to continue on > the next line. > > Has this issue been discussed already? > > slehar Use subroutines. -- http://mail.python.org/mailman/listinfo/python-list
RE: xml-rpc server on wine
>> Hi, I have a XML-RPC server python running on VM Windows (on Linux) >> and a XML-RPC client python on Linux. Server and client have different >> IP address. I'd like migrate server on wine. How can communicate >> server and client? IP address is different or is the same? >> Can you help me? >Not really, this doesn't have much of anything to do with Python. If >you run a network application on wine [assuming that even works] the >application will have the same IP/interface as any other application or >service running on the host. Wine is not a 'virtualization' solution. Unless you have a specific need to run it in a virtual machine (which WINE is not), why not run it directly from Linux? I generally prefer to use a DNS name or hostname to connect instead of IP because the IP addresses can be dynamic (especially when you start accessing it from outside your local network). Even internally, I tend to use hostnames and not IP addresses, but mostly because it is faster/easier for me to type (I assign static IPs internally). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help catching error message
On Tue, 08 Nov 2011 05:20:51 -0800, Gnarlodious wrote: > What I say is this: > > def SaveEvents(self,events): >try: > plistlib.writePlist(events, self.path+'/Data/Events.plist') # > None if OK >except IOError: > return "IOError: [Errno 13] Apache can't write Events.plist > file" > > Note that success returns"None" while failure returns a string. I started off writing a sarcastic response about people who refuse to learn idiomatic Python and instead insist on writing (e.g.) Java or PHPP in Python. But then I eventually got to the *very last line* of your post where you noted that you were doing this in WSGI. For future reference, when writing unidiomatic code *deliberately*, please say so up front, at the start of your message rather than at the end, and save your readers (or at least *me*) from jumping to the wrong conclusion. Change the function to this: def SaveEvents(self,events): try: plistlib.writePlist(events, self.path+'/Data/Events.plist') return '' except IOError as e: return str(e) # or if you prefer, your own custom error string # "IOError: [Errno 13] Apache can't write Events.plist file" I return a string in both cases so that you can, if you choose, use the output of SaveEvents anywhere where a string is expected without worrying about whether it returns None or a string: content = Data.Dict.SaveEvents(Data.Plist.Events) # content will be the empty string if no error, otherwise error message. If you don't care about that, just delete the return '' line and the function will fall back on returning None by default. Either way, you can also use it like this: content = Data.Dict.SaveEvents(Data.Plist.Events) or content This will leave content unchanged if no error is returned, otherwise it will replace the value. Note that content must have an initial value to start with (presumably the empty string). -- Steven -- http://mail.python.org/mailman/listinfo/python-list
getting command line in python
Hi people! I am looking for a way to get the command line in the script. Let us say I am in the folder "/tmp" okay! now from /tmp I execute in the console this: python /home/tamer/MyApp/MyScript.py in the app itself, I want to grep the path and the scriptname itself, like: /home/tamer/MyApp is being somewhere available. Tamer -- http://mail.python.org/mailman/listinfo/python-list
Re: getting command line in python
On 8-11-2011 23:19, MrSmile wrote: Hi people! I am looking for a way to get the command line in the script. Let us say I am in the folder "/tmp" okay! now from /tmp I execute in the console this: python /home/tamer/MyApp/MyScript.py in the app itself, I want to grep the path and the scriptname itself, like: /home/tamer/MyApp is being somewhere available. Tamer sys.argv Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: getting command line in python
On Tue, Nov 8, 2011 at 2:19 PM, MrSmile wrote: > Hi people! > I am looking for a way to get the command line in the script. > > Let us say I am in the folder "/tmp" okay! > > now from /tmp I execute in the console this: > python /home/tamer/MyApp/MyScript.py > > in the app itself, I want to grep the path and the scriptname itself, > like: /home/tamer/MyApp is being somewhere available. Under your example conditions: sys.argv[0] will be "/home/tamer/MyApp/MyScript.py". (A) os.getcwd() will return "/tmp". (B) The `os.path` module is also very relevant: http://docs.python.org/library/os.path.html Cheers, Chris -- http://rebertia.com (A): http://docs.python.org/library/sys.html#sys.argv (B): http://docs.python.org/library/os.html#os.getcwd -- http://mail.python.org/mailman/listinfo/python-list
Re: getting command line in python
On 08Nov2011 23:19, MrSmile wrote: | I am looking for a way to get the command line in the script. | | Let us say I am in the folder "/tmp" okay! | | now from /tmp I execute in the console this: | python /home/tamer/MyApp/MyScript.py | | in the app itself, I want to grep the path and the scriptname itself, | like: /home/tamer/MyApp is being somewhere available. Have you looked in sys.argv[0]? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It is not true that life is one damn thing after another -- it's one damn thing over and over.- Edna St. Vincent Millay -- http://mail.python.org/mailman/listinfo/python-list
Re: getting command line in python
Thank you all, that was it that I was searching for you. Tamer Am 08.11.2011 23:32, schrieb Cameron Simpson: > On 08Nov2011 23:19, MrSmile wrote: > | I am looking for a way to get the command line in the script. > | > | Let us say I am in the folder "/tmp" okay! > | > | now from /tmp I execute in the console this: > | python /home/tamer/MyApp/MyScript.py > | > | in the app itself, I want to grep the path and the scriptname itself, > | like: /home/tamer/MyApp is being somewhere available. > > Have you looked in sys.argv[0]? -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On 2:59 PM, Chris Angelico wrote: >>> So really, it's not "all() is slow" but "function calls are slow". >>> Maybe it'd be worthwhile making an all-factory: >> PLEASE say you're joking. If I saw code like that on any of our project, >> this would definitely qualify for a DailyWTF. > For the benefit of anyone who was actually in doubt: YES, I was > joking. Do *not* put code like this into any production project. Because an all-factory would produce code smell? :-) -- http://mail.python.org/mailman/listinfo/python-list
Decouplable CMS in python?
:)I'm sure decouplable is a word. If not it should be. I have written my own framework. This has been a work in progress as a consequence of projects that I have done over the last 10 years. I need a CMS that sits "on top of" the framework. One of the starting points that I have considered is finding a fairly simple, but well-written CMS in python and adapting it. It may very well turn out that I would have to start from 'scratch', nevertheless, reviewing code for such a simple CMS would be informative. I'm thinking that, as an example - django-cms - would be too complex, regardless of its merits. Any recommendations? thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On 11/08/2011 04:51 PM, John Posner wrote: On 2:59 PM, Chris Angelico wrote: So really, it's not "all() is slow" but "function calls are slow". Maybe it'd be worthwhile making an all-factory: PLEASE say you're joking. If I saw code like that on any of our project, this would definitely qualify for a DailyWTF. For the benefit of anyone who was actually in doubt: YES, I was joking. Do *not* put code like this into any production project. Because an all-factory would produce code smell? :-) Groan...that word-play is the pits! :) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: overview on dao
On Nov 9, 1:52 am, Dennis Lee Bieber wrote: > On Mon, 7 Nov 2011 21:10:59 -0800 (PST), Simeon Chaos > declaimed the following in > gmane.comp.python.general: > > > Dao is a a functional logic solver (similar to lambdaProlog, Curry) > > written in python. The links related to dao are here: > > Unfortunately the name is in conflict with M$ DAO (Data Access > Objects), the precursor to ADO. Every time I see "Dao" my mind goes "JET > database". > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/ Yeah, here "dao" is from The book of Dao" by Laozi, means the way of the world go. -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
Clearly what we need is a modern hygienic macro system to avoid this exec mess! defmacro defall(name, cond): def name(lst): for a in lst: if not cond: return False return True invoke defall(all, cond) Only slightly tongue in cheek. We have that stupid exec trick in the Python stdlib. It has to die. http://hg.python.org/cpython/file/6bf07db23445/Lib/collections/__init__.py#l240 Devin On Mon, Nov 7, 2011 at 5:06 PM, Chris Angelico wrote: > On Tue, Nov 8, 2011 at 8:46 AM, david vierra wrote: >> But, you didn't write an all() function. You wrote a more specialized >> allBoolean() function. I think this comparison is more fair to the >> builtin all(): > > So really, it's not "all() is slow" but "function calls are slow". > Maybe it'd be worthwhile making an all-factory: > > def my_all(code,lst): > exec("""def tmp_all(x): > for a in x: > if not ("""+code+"""): return False > return True > """) > return tmp_all(lst) > timeit.timeit('my_all("a in (True, False)",x)','from __main__ import > my_all,x',number=10) > > Bad code imho, but it _is_ faster than both the original and the builtin. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: overview on dao
On 09/11/2011 00:13, Simeon Chaos wrote: On Nov 9, 1:52 am, Dennis Lee Bieber wrote: On Mon, 7 Nov 2011 21:10:59 -0800 (PST), Simeon Chaos declaimed the following in gmane.comp.python.general: Dao is a a functional logic solver (similar to lambdaProlog, Curry) written in python. The links related to dao are here: Unfortunately the name is in conflict with M$ DAO (Data Access Objects), the precursor to ADO. Every time I see "Dao" my mind goes "JET database". -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ Yeah, here "dao" is from The book of Dao" by Laozi, means the way of the world go. Perhaps you should call it "LaoZiDao". -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On Wed, Nov 9, 2011 at 11:44 AM, Devin Jeanpierre wrote: > Clearly what we need is a modern hygienic macro system to avoid this exec > mess! > > defmacro defall(name, cond): > def name(lst): > for a in lst: > if not cond: > return False > return True #define defall(name,cond) def name(lst): \ for a in lst: \ if not cond: return False \ return True gcc -E myprog.pyi -o myprog.py There's no code you can't make more opaque using the C preprocessor. Python doesn't have inline functions? Ha! In your FACE, evil Python development cabal! You can't tell ME what I can't do! ChrisA PS. Don't try this at home. We have years of experience with bad code. Don't write code like this unless you have a life insurance policy that covers angry mobs. -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On Tue, Nov 8, 2011 at 5:19 PM, Chris Angelico wrote: > On Wed, Nov 9, 2011 at 11:44 AM, Devin Jeanpierre > wrote: >> Clearly what we need is a modern hygienic macro system to avoid this exec >> mess! >> >> defmacro defall(name, cond): >> def name(lst): >> for a in lst: >> if not cond: >> return False >> return True > > #define defall(name,cond) def name(lst): \ > for a in lst: \ > if not cond: return False \ > return True > > gcc -E myprog.pyi -o myprog.py > > There's no code you can't make more opaque using the C preprocessor. > > Python doesn't have inline functions? Ha! In your FACE, evil Python > development cabal! You can't tell ME what I can't do! > > ChrisA > PS. Don't try this at home. We have years of experience with bad code. > Don't write code like this unless you have a life insurance policy > that covers angry mobs. Burn him! Witch! Witch! Burn him! His code turned me into a newt! -- Sent nailed to a coconut carried by swallow. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help catching error message
On Nov 8, 3:16 pm, Steven D'Aprano wrote: > content = Data.Dict.SaveEvents(Data.Plist.Events) or content > > This will leave content unchanged if no error is returned, otherwise it > will replace the value. Ah, the 'or' operator does it. Thank you, that is exactly what I was looking for. I should confess, I am not a programmer and don't even know what "idiomatic" means in this context. I don't know Java or PHP, only a little Forth from the HP calculator era. Advanced topics I just skip over because I don't understand them. But I am learning slowly and appreciate the help. -- Rachel http://Sectrum.com -- http://mail.python.org/mailman/listinfo/python-list
Re: all() is slow?
On Tue, 08 Nov 2011 19:44:18 -0500, Devin Jeanpierre wrote: > We have that stupid exec trick in the Python stdlib. It has to die. > > http://hg.python.org/cpython/file/6bf07db23445/Lib/collections/__init__.py#l240 http://bugs.python.org/issue3974 http://blog.ccpgames.com/kristjan/2011/05/28/namedtuple-and-exec/ If it were someone other than Raymond Hettinger responsible for the use of exec in namedtuple, I'd be a lot more suspicious of it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Help catching error message
On Tue, 08 Nov 2011 17:48:57 -0800, Gnarlodious wrote: > On Nov 8, 3:16 pm, Steven D'Aprano wrote: > >> content = Data.Dict.SaveEvents(Data.Plist.Events) or content >> >> This will leave content unchanged if no error is returned, otherwise it >> will replace the value. > Ah, the 'or' operator does it. Thank you, that is exactly what I was > looking for. > > I should confess, I am not a programmer and don't even know what > "idiomatic" means in this context. I don't know Java or PHP, only a > little Forth from the HP calculator era. Advanced topics I just skip > over because I don't understand them. But I am learning slowly and > appreciate the help. Idiomatic in this context means that the code follows standard styles, patterns or techniques commonly accepted by most good programmers of the language. This implies that the code works with the language, playing to its strengths, rather than against it. Non-idiomatic code tends to be slower than it could be, or harder to read, or harder to maintain, or all three. Idiomatic is relative to the language: what is idiomatic for one language may not be for another. For instance, if I were to ask "How do I do something with each item of a list?", the idiomatic way in Python would be: for item in some_list: do_something_with(item) rather than: for i in range(len(some_list)): item = some_list[index] do_something_with(item) and especially not this: index = 0 while index < len(some_list): item = some_list[index] do_something_with(item) index += 1 Regards, -- Steven -- http://mail.python.org/mailman/listinfo/python-list