Re: Imports awareness in Imported modules problem
Mohamed Yousef wrote: why am i doing this in the first place I'm in the process of a medium project where imports of modules start to make a jungle and i wanted all needed imports to be in a single file (namely __init__.py) and then all imports are made once and other modules feel it Python doesn't use a global namespace -- importing a given module into one module doesn't make it visible everywhere else (and trust me, this is a very good thing). (it uses a global module cache, though, so it's only the first import that actually loads the module) > my goal is basically making W() aware of the re module when called > from A to do that, add "import re" to the top of the C module. see this page for a little more on Python's import mechanism: http://effbot.org/zone/import-confusion.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Top 10 Things To Look For In A Web Host
best_hosting <[EMAIL PROTECTED]> writes: > Top 10 Things To Look For In A Web Host 1. They don't spam 2. They don't spam 3.-9. They don't spam 10. They don't spam. -- http://mail.python.org/mailman/listinfo/python-list
Re: Psyco == tracing optimization?
Banibrata Dutta wrote: AFAIK, the same logic used in runtime optimization of several other dynamic languages or shell-scripting languages (including Perl), for quite a while. Trace trees are widely used? Got any references for that? -- http://mail.python.org/mailman/listinfo/python-list
Re: Top 10 Things To Look For In A Web Host
Paul Rubin wrote: Top 10 Things To Look For In A Web Host 1. They don't spam 2. They don't spam 3.-9. They don't spam 10. They don't spam. http://tinyurl.com/blogspot-spam (or if you're using gmail to read the list, just flag as spam and you're done) -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
W. eWatson schreef: I completed a Win Python program and it has generated the necessary data, which I have in turn used successfully with the telescope software. Is there some way to turn this into an executable program for people who do not have Python? Yes, you can use py2exe (http://www.py2exe.org/) for that. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Cross Platform, Curses-Style Text Editor?
I'm writing a little 'command line simulator' in Python. It runs completely within regular command lines, using simple prints and raw_inputs. I need to code a text editor for editing the virtual files in the simulation. It needs to function somewhat like pywarrior (ubuntuforums.org/showthread.php?t=866035), although simplified, of course. However, I'd like it to run on as many platforms as possible. pywarrior only runs on Linux/Mac OS, probably due to the 'curses' module. Is there a cross-platform way to write a simple, pywarrior-esque text editor? -- http://mail.python.org/mailman/listinfo/python-list
No method overloading
Hey, Please correct me if I'm wrong but Python doesn't support method overload, right? -- def method(self): #code def method(self, data): #code -- The last declaration of method() erase the previous one (like JavaScript). Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: No method overloading
On Aug 24, 6:15 pm, Hussein B <[EMAIL PROTECTED]> wrote: > Hey, > Please correct me if I'm wrong but Python doesn't support method > overload, right? > -- > def method(self): > #code > def method(self, data): > #code > -- > The last declaration of method() erase the previous one (like > JavaScript). > Thanks. Correct. The second declaration overwrites the first. Give data a default argument instead: def method(self, data=None): if data is None: # Normal code else: # data included code Not sure how Pythonic that is, but it should work the way you're requesting... I think. -- http://mail.python.org/mailman/listinfo/python-list
Re: No method overloading
Hussein B wrote: Please correct me if I'm wrong but Python doesn't support method overload, right? -- def method(self): #code def method(self, data): #code -- The last declaration of method() erase the previous one (like JavaScript). in Python, methods are callable attributes, and an attribute can only have one value. you can use default arguments to work around this: def method(self, data=None): if data is None: #code else: #code -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
What modules do I need to use pylab? I've installed scipy and numpy. http://matplotlib.sourceforge.net/ -- Have Fun, David A. Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com -- http://mail.python.org/mailman/listinfo/python-list
What is class method?
Hi, I'm familiar with static method concept, but what is the class method? how it does differ from static method? when to use it? -- class M: def method(cls, x): pass method = classmethod(method) -- Thank you for your time. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is class method?
On Aug 24, 6:32 pm, Hussein B <[EMAIL PROTECTED]> wrote: > Hi, > I'm familiar with static method concept, but what is the class method? > how it does differ from static method? when to use it? > -- > class M: > def method(cls, x): > pass > > method = classmethod(method) > -- > Thank you for your time. Firstly, don't use method = classmethod(method). Decorators are far better. The following code has the same effect: class M: @classmethod def method(cls, x): pass Far more readable, right? Class methods are useful if you've got lots of inheritance happening. The first argument passed in is the class calling the method. Handy for a mix-in: it can add methods affecting the actual class it's mixed into, rather than messing with the mix-in itself. -- http://mail.python.org/mailman/listinfo/python-list
Interrupt python thread
Hi, I have a program with a master thread and several slave threads. Whenever an exception occurs, in the master thread or in one of the slave threads, I would like to interrupt all the threads and the main program. Threading API does not seem to provide a way to stop a thread, is there anyway to achieve that ? The closest thing I found is thread.interrupt_main() but it's far from perfect : - it only allow to interrupt the main thread - if the main thread is sleeping, it does not interrupt it (at least on windows) cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: What is class method?
Hussein B <[EMAIL PROTECTED]> writes: > Hi, > I'm familiar with static method concept, but what is the class method? > how it does differ from static method? when to use it? > -- > class M: > def method(cls, x): > pass > > method = classmethod(method) Use it when your method needs to know what class it is called from. This makes sense in the context of subclassing: class M(object): @classmethod def method(cls, x): print cls, x class N(M): pass >>> M.method(1) 1 >>> N.method(1) 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Psyco == tracing optimization?
On Aug 24, 8:11 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Banibrata Dutta wrote: > > AFAIK, the same logic used in runtime optimization of several other > > dynamic languages or shell-scripting languages (including Perl), for > > quite a while. > > Trace trees are widely used? Got any references for that? > > I too feel that if Perl had such optimizations as Psyco gives Python then they would shout about it. I wonder about the new term and if it fits in the same 'box' as what Psyco does, for example, who was aware of whose work? - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: No method overloading
On Aug 24, 6:15 pm, Hussein B <[EMAIL PROTECTED]> wrote: > Please correct me if I'm wrong but Python doesn't support method > overload, right? Guido once wrote an article on rolling your own: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 -- http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
castironpi <[EMAIL PROTECTED]> wrote: > and we'll write Python. I haven't seen anything you've contributed to this group that would so far be considered well-written Python. Confusing and border-line insane, yes. Pythonic? Not at all. Here's a tip: try actually developing some real-world application in Python for a while, rather than the god-knows-what-you're-doing attempts that you keep hijacking various threads with. Your code isn't anywhere near as clever as you seem to think. -- http://mail.python.org/mailman/listinfo/python-list
Best way to set/get an object property
Hey, I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. What if I want to run some logic upon setting/getting a property? What is Python preferred method to do so (using the new feature 'property')? I don't think __getattr__ and __setattr__ are practical (I have to code the property name into them). Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports visibility in imported modules problem
On Sun, Aug 24, 2008 at 5:54 AM, Patrick Maupin <[EMAIL PROTECTED]> wrote: > On Aug 23, 7:27 pm, "Mohamed Yousef" <[EMAIL PROTECTED]> wrote: > >> The problem I'm asking about is how can imported modules be aware of >> other imported modules so they don't have to re-import them (avoiding >> importing problems and Consicing code and imports ) > > You could import sys and look at sys.modules no even if you imported sys or used dir you will see no re in W() from A . and you can even try to use re and will see >> why am i doing this in the first place I'm in the process of a medium >> project where imports of modules start to make a jungle and i wanted >> all needed imports to be in a single file (namely __init__.py) and >> then all imports are made once and other modules feel it > > This doesn't sound like a good idea. If A imports a module which is > automatically imported into B's namespace, that sounds like a > maintenance nightmare. why ? this saves time and consices whole package imports in one file and maintaining it is easier (eg. you will never have circuular imports) >> >> another reason to do this that my project is offering 2 interfaces >> (Console and GUI through Qt) and i needed a general state class ( >> whether i'm in Console or GUI mode) to be available for all , for >> determining state and some public functions ,and just injecting >> Imports everywhere seems a bad technique in many ways (debugging , >> modifying ...etc ) > > I still don't understand. put it another way a general variable in all modules and some functions visible in all modules >> in PHP "Require" would do the trick neatly ... so is there is >> something I'm missing here or the whole technique is bad in which case >> what do you suggest ? > > I don't know what to suggest, in that you haven't yet stated anything > that appears to be a problem with how Python works. If two different > modules import the same third module, there is no big performance > penalty. The initialization code for the third module is only > executed on the first import, and the cost of having the import > statement find the already imported module is trivial. it's not performance it's the jungle resulting many imports in every file and suppose i changed the module used in all modules name guess what , it will have to be renamed in every import to it in all modules -- http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
On Aug 22, 1:18 pm, David Moss <[EMAIL PROTECTED]> wrote: > It works well enough, but I can't help feeling there a cleaner more > readable way of doing this (with less duplication, etc). > > Is this as good as it gets or can this be refined and improved > especially if I was to add in a couple more attributes some fairly > complex over-ride logic? > > #!/usr/bin/env python > > class A(object): > def __init__(self): > self._x = None > self._y = None > > def _set_x(self, value): > self._x = value > > def _get_x(self): > return self._x > > x = property(_get_x, _set_x) > > def _set_y(self, value): > self._y = value > > def _get_y(self): > return self._y > > y = property(_get_y, _set_y) FWIW, there is a variant of property() that allows you to re-use the same getter/setter code for multiple attributes: http://code.activestate.com/recipes/205126/ Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list
Re: EOF
En Fri, 22 Aug 2008 16:53:58 -0300, Wojtek Walczak <[EMAIL PROTECTED]> escribió: > On Fri, 22 Aug 2008 22:18:37 +0530, Anjanesh Lekshminarayanan wrote: > >> Im trying to download a file from a server. But how do I detect EOF ? > > Whenever read() method returns empty string/list. > > >> while f1: # When to stop ? > retval = f1.read() > if not retval: > break > f2.write(retval) Those read() should be read(size) - read() tries to get the whole contents in memory. Anyway, shutil.copyfileobj already implements that logic. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports awareness in Imported modules problem
On Sun, Aug 24, 2008 at 9:59 AM, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Mohamed Yousef wrote: > >> why am i doing this in the first place >> I'm in the process of a medium project where imports of modules start >> to make a jungle and i wanted all needed imports to be in a single >> file (namely __init__.py) >> and then all imports are made once and other modules feel it > > Python doesn't use a global namespace -- importing a given module into one > module doesn't make it visible everywhere else (and trust me, this is a very > good thing). why isn't it a good thing (even if optional) consider the sitution in which a utility module is used every where else - other modules - you may say import it in them all , what i changed it's name ? go back change all imports... this doesn't seem good and what about package wide varailbles ? > (it uses a global module cache, though, so it's only the first import that > actually loads the module) > >> my goal is basically making W() aware of the re module when called >> from A > > to do that, add "import re" to the top of the C module. and sys ,string.. etc add them all twice or four / n times ? remove one and then forget to remove one of them in a file and start debugging ... this really doesn't look to be a good practice > see this page for a little more on Python's import mechanism: > >http://effbot.org/zone/import-confusion.htm > Regards, Mohamed Yousef -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to set/get an object property
Hussein B wrote: > I noted that Python encourage the usage of: > -- > obj.prop = data > x = obj.prop > -- > to set/get an object's property value. > What if I want to run some logic upon setting/getting a property? > What is Python preferred method to do so (using the new feature > 'property')? > I don't think __getattr__ and __setattr__ are practical (I have to > code the property name into them). Hussein, I don't think you'll learn much from asking these abstract questions. At some point you have to get your hands dirty and write actual code to get a feel for the language. For example, it will then become obvious for you that property works best for individual attributes while __getattr__ and friends are more convenient if you want to treat multiple attributes the same way, attributes whose names may not even be known until runtime (think delegation). Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to set/get an object property
On Aug 24, 5:28 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Hussein B wrote: > > I noted that Python encourage the usage of: > > -- > > obj.prop = data > > x = obj.prop > > -- > > to set/get an object's property value. > > What if I want to run some logic upon setting/getting a property? > > What is Python preferred method to do so (using the new feature > > 'property')? > > I don't think __getattr__ and __setattr__ are practical (I have to > > code the property name into them). > > Hussein, I don't think you'll learn much from asking these abstract > questions. At some point you have to get your hands dirty and write actual > code to get a feel for the language. > > For example, it will then become obvious for you that property works best > for individual attributes while __getattr__ and friends are more convenient > if you want to treat multiple attributes the same way, attributes whose > names may not even be known until runtime (think delegation). > > Peter Thanks Peter, You are right, I have to try to touch the Python but the problem is I don't have much time to do so. I have a Java developer for more than 4 years and I find it is not so easy to digest Python concepts, this is why I'm asking a lot of obvious and clear easy to you (long time Pythonists). Thank you for your time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports awareness in Imported modules problem
On Aug 24, 8:34 pm, "Mohamed Yousef" <[EMAIL PROTECTED]> wrote: > and sys ,string.. etc add them all twice or four / n times ? > remove one and then forget to remove one of them in a file and start > debugging ... this really doesn't look to be a good practice No, having each module contain all of the necessary imports for itself -is- good practice. While it might seem more convenient to define all of your imports in one place, what you're really doing is injecting -all- references to - all- imported items into -every- module. Having a global soup of imported items like such is much, much harder to control for unexpected name conflicts. Ideally, you want each module's namespace to -only- contain references to the external entities it's actually using. This not only makes each module self-contained and more open to independent re-use, it makes them -incredibly- easier to debug. Please don't confuse temporary convenience with good practice. -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports awareness in Imported modules problem
On Sun, Aug 24, 2008 at 2:27 PM, alex23 <[EMAIL PROTECTED]> wrote: > On Aug 24, 8:34 pm, "Mohamed Yousef" <[EMAIL PROTECTED]> wrote: >> and sys ,string.. etc add them all twice or four / n times ? >> remove one and then forget to remove one of them in a file and start >> debugging ... this really doesn't look to be a good practice > > No, having each module contain all of the necessary imports for itself > -is- good practice. > > While it might seem more convenient to define all of your imports in > one place, what you're really doing is injecting -all- references to - > all- imported items into -every- module. Having a global soup of > imported items like such is much, much harder to control for > unexpected name conflicts. > > Ideally, you want each module's namespace to -only- contain references > to the external entities it's actually using. This not only makes each > module self-contained and more open to independent re-use, it makes > them -incredibly- easier to debug. > > Please don't confuse temporary convenience with good practice. mm , this seems to be logically or another good behind logic . as PHP already uses that convention -from which i thought python also does - but what about module-wide variables what is the approach to them , will i have to store them in a memory table (SQL) , or keep passing them between objects - which i really hate - -- http://mail.python.org/mailman/listinfo/python-list
Re: How to search the Python manuals
2008/8/22 Terry Reedy <[EMAIL PROTECTED]>: [snip] > On the left, click [+] for Language Reference > (3.0: The Python language reference). "Language Reference (for language lawyers)" Language Lawyer? That's almost as worser than Grammar Nazi, no wonder no one is finding anything there. -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question about sending and receiving data to the command prompt.
En Fri, 22 Aug 2008 18:25:49 -0300, n00m <[EMAIL PROTECTED]> escribió: > Is it possible to communicate in loop fashion? > > > import subprocess as s > proc = s.Popen('cmd.exe', stdin=s.PIPE, stdout=s.PIPE) > while 1: > cmd = raw_input('cmd:') > res = proc.communicate(cmd + '\n')[0] > print res > Don't use communicate, it waits for the process to finish. But you can write and read from the pipes. The hard part is to recognize *where* output from the previous command ends (so you don't read further). The code below uses #\n as the prompt: import subprocess as s def read_output(stdout): while 1: line = stdout.readline() if not line: break line = line.rstrip('\r\n') if line=='#': break yield line proc = s.Popen('cmd.exe /k prompt #$_', stdin=s.PIPE, stdout=s.PIPE) for line in read_output(proc.stdout): pass # skip over initial prompt while 1: cmd = raw_input('cmd:') proc.stdin.write(cmd+'\n') for line in read_output(proc.stdout): print line -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Psyco == tracing optimization?
Apologies for the inaccurate comment, without completely researching the "Trace trees" logic. Indeed, it is not apparent that Perl or other common languages use it or have used it for long. On 8/24/08, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > Banibrata Dutta wrote: > > AFAIK, the same logic used in runtime optimization of several other dynamic >> languages or shell-scripting languages (including Perl), for quite a while. >> > > Trace trees are widely used? Got any references for that? > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- regards, Banibrata http://www.linkedin.com/in/bdutta http://octapod.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Regex on a huge text
On Aug 22, 9:19 pm, "Medardo Rodriguez" <[EMAIL PROTECTED]> wrote: > On Fri, Aug 22, 2008 at 11:24 AM, Dan <[EMAIL PROTECTED]> wrote: > > I'm looking on how to apply a regex on a pretty huge input text (a file > > that's a couple of gigabytes). I found finditer which would return results > > iteratively which is good but it looks like I still need to send a string > > which would be bigger than my RAM. Is there a way to apply a regex directly > > on a file? > > > Any help would be appreciated. > > You can call *grep* posix utility. > But if the regex's matches are possible only inner the context of a > line of that file: > # > res = [] > with file(filename) as f: > for line in f: > res.extend(getmatches(regex, line)) > # Of course "getmatches" describes the concept. > # > > Regards Try and pre-filter your file on a line basis to cut it down , then apply a further filter on the result. For example, if you were looking for consecutive SPAM records with the same Name field then you might first extract only the SPAM records from the gigabytes to leave something more manageable to search for consecutive Name fields in. - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports awareness in Imported modules problem
On Aug 24, 9:43 pm, "Mohamed Yousef" <[EMAIL PROTECTED]> wrote: > but what about module-wide variables what is the approach to them , > will i have to store them in a memory table (SQL) , or keep passing > them between objects - which i really hate - If you have a set of global variables that you want to share among modules, put them all into a module. config.py: var1 = 'a' a.py: import config config.var1 = 'z' b.py: import config print config.var1 >>> import a >>> import b z A module is only really imported once; each subsequent import is given a reference to that imported module, so any changes to the module values are shared amongst each importing module. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Importance of Terminology's Quality
On Sat, 23 Aug 2008 21:22:05 -0400, John W Kennedy wrote: > Martin Gregorie wrote: >> On Sat, 23 Aug 2008 00:06:28 -0400, John W Kennedy wrote: >> >>> Martin Gregorie wrote: Not necessarily. An awful lot of CPU cycles were used before microcode was introduced. Mainframes and minis designed before about 1970 didn't use or need it >>> No, most S/360s used microcode. >> >> I never used an S/360. >> >> I thought microcode came into the IBM world with S/370 and Future >> Series (which later reappeared as the AS/400, which I did use). Didn't >> the S/370 load its microcode off an 8 inch floppy? > > Some did, but not all. The 370/145 was the first, and made a big splash > thereby. > ..snip... Thanks for that. As I said, during most of that era I was using ICL kit. Microcode was never mentioned in the 1900 contect. Hoiwever, they had a very rough approximation called extracodes. though they were closer to software traps than microcode: if hardware didn't implement an op code the OS intercepted it and ran equivalent code. This was used for i/o operations and for FP instructions on boxes that didn't have FP hardware. As a result all boxes executed the same instruction set. Some opcodes might be very slow on some hardware but it would execute. The 2900 series had huge amounts of microcode - it even defined both memory mapping and opcodes. You could run 1900 code (24 bit words, fixed length instructions, ISO character codes) simultaneously with 'native' code (8 bit bytes, v/l instructions, EBCDIC) with each program running under its usual OS (George 3 for 1900, VME/B for 1900). The only other systems I'm aware of that could do this were the big Burroughs boxes (6700 ?), which used a byte-based VM for COBOL and a word- based VM for FORTRAN and Algol 60) and IBM AS/400 (OS/400 could run S/34 code alongside S/38 and AS/400 code). AFAICT Intel virtualisation doesn't do this - all code running under VMware or any of the other VMs is still running in a standard Intel environment. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | -- http://mail.python.org/mailman/listinfo/python-list
tax is importent life in after we family
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Hai you looking Real Esate Agents India
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
get more info for your bright future
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
get more info for your bright future
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
you play football games click here
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
heavanly place
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
gender beutiful clever
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
so many model click here
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports awareness in Imported modules problem
Mohamed Yousef wrote: mm , this seems to be logically or another good behind logic . as PHP already uses that convention -from which i thought python also does - I'm not sure arguing with anyone who tries to help you is the best way to learn a new programming language. -- http://mail.python.org/mailman/listinfo/python-list
Re: A variables variables
Le Sunday 24 August 2008 03:24:29 Terry Reedy, vous avez écrit : > Gandalf wrote: > > how can I declare a variable with another variable name? > > > > for example I will use PHP: > > > > $a= "hello"; > > > > $a_hello="baybay"; > > > > print ${'a_'.$a) //output: baybay > > > > > > how can i do it with no Arrays using python > > Others have given you the direct answer. Well using locals() is the right answer, it is a very bad use case for eval. > But using lists or dicts is > almost always a better solution in Python than synthesizing global/local > namespace names. > > a={'hello':'baybay'} > print a['hello'] But locals() *is* an already made dict, very convenient for use locally and read-only. >>>[155]: var1 = "easy" >>>[156]: var2 = "proper" >>>[157]: var3 = "locals" >>>[158]: print "a %(var2)s and %(var1)s use of %(var3)s with %(var3)s()" % locals() a proper and easy use of locals with locals() -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
On Aug 24, 5:00 am, alex23 <[EMAIL PROTECTED]> wrote: > castironpi <[EMAIL PROTECTED]> wrote: > > and we'll write Python. > > I haven't seen anything you've contributed to this group that would so > far be considered well-written Python. > > Confusing and border-line insane, yes. Pythonic? Not at all. > > Here's a tip: try actually developing some real-world application in > Python for a while, rather than the god-knows-what-you're-doing > attempts that you keep hijacking various threads with. Your code isn't > anywhere near as clever as you seem to think. Python isn't as clever as you think. It's a language. Do you want a link to clever code? I like to encourage creativity. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is class method?
On Aug 24, 3:35 am, MeTheGameMakingGuy <[EMAIL PROTECTED]> wrote: > On Aug 24, 6:32 pm, Hussein B <[EMAIL PROTECTED]> wrote: > > > Hi, > > I'm familiar with static method concept, but what is the class method? > > how it does differ from static method? when to use it? > > -- > > class M: > > def method(cls, x): > > pass > > > method = classmethod(method) > > -- > > Thank you for your time. > > Firstly, don't use method = classmethod(method). Decorators are far > better. The following code has the same effect: > > class M: > [EMAIL PROTECTED] > def method(cls, x): > pass > > Far more readable, right? > > Class methods are useful if you've got lots of inheritance happening. > The first argument passed in is the class calling the method. Handy > for a mix-in: it can add methods affecting the actual class it's mixed > into, rather than messing with the mix-in itself. It is similar to: class M: #not correct as shown def newmaker( self, x ): newinst= self.__class__( arg1, arg2, x ) return newinst m1= M() m2= m1.newmaker( 'abc' ) except you don't need the first instance to do it with. Notice you get a new instance of whatever class m1 is an instance of, rather than necessarily M. class N( M ): pass m1= N() m2= m1.newmaker( 'abc' ) m2 is of class N now too. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to set/get an object property
On Aug 24, 5:07 am, Hussein B <[EMAIL PROTECTED]> wrote: > Hey, > I noted that Python encourage the usage of: > -- > obj.prop = data > x = obj.prop > -- > to set/get an object's property value. > What if I want to run some logic upon setting/getting a property? > What is Python preferred method to do so (using the new feature > 'property')? > I don't think __getattr__ and __setattr__ are practical (I have to > code the property name into them). > Thanks. The answer Hussein is you have both options in Python. If neither one is clearly better-suited to your new application, pick one and go. -- http://mail.python.org/mailman/listinfo/python-list
recursively change values in list of lists
Dear list, I'm sure this is a relatively trivial problem, but I have been unable to find any good examples/explanations on how to do this, so here goes: I have multi-polygon object, which is simply a list of polygons, where each polygon is a list of lines, where each line is a list of points. What I would like to do, is change the x and y values of each point, all the while keeping the structure of the lists intact. So in the end, the only thing that should be changed is the values, not the lists themselves... clear as mud? Any hints, and/or suggestions are greatly appreciated, Carson -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
David wrote: What modules do I need to use pylab? I've installed scipy and numpy. http://matplotlib.sourceforge.net/ I'm using Python 2.4. The install looks pretty complicated for Windows. It doesn't seem like matplotlib is a module. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet Web Page: -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports visibility in imported modules problem
Le Sunday 24 August 2008 12:11:03 Mohamed Yousef, vous avez écrit : > On Sun, Aug 24, 2008 at 5:54 AM, Patrick Maupin <[EMAIL PROTECTED]> wrote: > > On Aug 23, 7:27 pm, "Mohamed Yousef" <[EMAIL PROTECTED]> wrote: > >> The problem I'm asking about is how can imported modules be aware of > >> other imported modules so they don't have to re-import them (avoiding > >> importing problems and Consicing code and imports ) > > > > You could import sys and look at sys.modules > > no even if you imported sys or used dir you will see no re in W() from > A . and you can even try to use re and will see > > >> why am i doing this in the first place I'm in the process of a medium > >> project where imports of modules start to make a jungle and i wanted > >> all needed imports to be in a single file (namely __init__.py) and > >> then all imports are made once and other modules feel it > > > > This doesn't sound like a good idea. If A imports a module which is > > automatically imported into B's namespace, that sounds like a > > maintenance nightmare. > > why ? > this saves time and consices whole package imports in one file > and maintaining it is easier Maintaining is easier ? Not at all, refactoring maybe but it's not a big deal, you must be convinced that module names are exactly as APIs, they are not intended to change between versions. BTW you could do that by importing all you need in one module, say libs.py, and from libs import * in all you r package modules. But htis considered a very bad practice by python developpers as PEP 8 states, it break on of the zen's rule : "explicit is better than implicit". Really, it is very good for reading and *maintaining* purpose to have all the names used in one's module be easily found in the few import statments at the top of the file. In case you really need to make available a name to an arbitrary piece of code (not a common scheme though), you could easily add it to the __builtin__ module, but if you know exactly what you do. > (eg. you will never have circuular imports) > No, circular imports are another problem that wouldn't be resolved by your suggestion. > >> another reason to do this that my project is offering 2 interfaces > >> (Console and GUI through Qt) and i needed a general state class ( > >> whether i'm in Console or GUI mode) to be available for all , for > >> determining state and some public functions ,and just injecting > >> Imports everywhere seems a bad technique in many ways (debugging , > >> modifying ...etc ) > > > > I still don't understand. > > put it another way a general variable in all modules > and some functions visible in all modules > This has no use case in python, even builtin names are overriden by the simple affectation stamtent, if you want to modify a global name, you need access it as an attribute of a specific namespace. glob.py: A=0 B=0 script.py: import glob from glob import A A=1 glob.B =1 print A, B, glob.A, glob.B will print 1, 1, 0, 1. > >> in PHP "Require" would do the trick neatly ... so is there is > >> something I'm missing here or the whole technique is bad in which case > >> what do you suggest ? > > > > I don't know what to suggest, in that you haven't yet stated anything > > that appears to be a problem with how Python works. If two different > > modules import the same third module, there is no big performance > > penalty. The initialization code for the third module is only > > executed on the first import, and the cost of having the import > > statement find the already imported module is trivial. > > it's not performance it's the jungle resulting > many imports in every file and suppose i changed the module used in > all modules name > guess what , it will have to be renamed in every import to it in all > modules -- (cf my previous comment). -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes initializer
On Aug 23, 7:11 pm, castironpi <[EMAIL PROTECTED]> wrote: > On Aug 23, 6:43 pm, [EMAIL PROTECTED] wrote: > > > > > castironpi napisa³(a): > > > > Is there a way to initialize a ctypes Structure to point to an offset > > > into a buffer? I don't know if the way I'm doing it is supported. > > > There is a high probability you're abusing ctypes too much, but it's > > possible. The following seems to work: > > > from ctypes import * > > > class S(Structure): > > _fields_ = [('x', c_uint), ('y', c_int)] > > rawdata = create_string_buffer('\xEE\xFF\x78\x56\x34\x12\xFF\xFF\xFF > > \xFF\xAA') > > > # Try to make a structure s of type S which takes its data from > > rawdata > > # buffer, starting at index 2 > > s = cast(c_void_p(addressof(rawdata)+2), POINTER(S)).contents > > > print hex(s.x), s.y # Should be 12345678h and -1 > > Output is 0x12345678L -1, as you state. I understand that '\xEE\xFF' > is skipped with addressof(rawdata)+ 2, which makes +2 an offset into > the buffer. > > At this point, I'd say the use of 'cast' is dubious, but possible to > support. My problem comes in, in that the buffer I have comes from a > non-ctypes source. It is a, mmap. > > My goals in exploring this are persistence and IPC, which are > certainly not abusing Python too much. 'ctypes' may not be right for > the job though. The solution I looked at got even worse than 'from > _ctypes import _cast_addr'. I want a supported way to do it. The solution could be as simple as returning a ctypes pointer from an mmap method. Does this require a PEP, or ought a patch to do it? -- http://mail.python.org/mailman/listinfo/python-list
PEP 8: Byte Order Mark (BOM) vs coding cookie
PEP 8 says ... Files using ASCII (or UTF-8, for Python 3.0) should not have a coding cookie. What about a BOM (Byte Order Mark)? Per Wikipedia ... http://en.wikipedia.org/wiki/Byte-order_mark#endnote_UTF-8) 'In UTF-8, this is not really a "byte order" mark. It identifies the text as UTF-8 but doesn't say anything about the byte order, because UTF-8 does not have byte order issues.' So is it good style to omit the BOM in UTF-8 for Python 3.0? -- http://mail.python.org/mailman/listinfo/python-list
Re: What is class method?
Le Sunday 24 August 2008 10:32:34 Hussein B, vous avez écrit : > Hi, > I'm familiar with static method concept, but what is the class method? > how it does differ from static method? when to use it? > -- > class M: > def method(cls, x): > pass > > method = classmethod(method) As it has been said, it adds polymorphic behavior to static method concept by the mean of a reference to the real class that called it. >>>[159]: class A(object) : .: @classmethod .: def factory(cls, *args) : return cls(*args) .: .: >>>[160]: class B(A) : .: def __init__(self, a, b) : .: print a, b .: .: >>>[161]: A.factory() ...[161]: <__main__.A object at 0x2b88d0e33710> >>>[162]: B.factory(1, 2) 1 2 ...[162]: <__main__.B object at 0x2b88d0e33bd0> It is a common advice that staticmethod should not exist in python, as they do nothing compared to module level functions, and we should always use classmethods in place of them. > -- > Thank you for your time. > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list
Re: recursively change values in list of lists
I see no recursion in the problem as stated. Can a polygon contain another polygon? I can see that if you had ... e_1 = [(0,0),(3,0)] e_2 = [(3,0),(2,3)] e_3 = [(2,3),(0,0)] triangle_1 = [e_1,e_2,e_3] w_1 = [triangle_1,] ... you might want to make a copy of triangle_1 that was offset by some amount and add it to w_1. Is that the idea? -- http://mail.python.org/mailman/listinfo/python-list
Re: recursively change values in list of lists
On Sun, Aug 24, 2008 at 10:17 AM, Carson Farmer <[EMAIL PROTECTED]> wrote: > So in the end, the only thing that should be changed is the values, > not the lists themselves... clear as mud? > > Any hints, and/or suggestions are greatly appreciated, You gave the solution yourself. I don't know if your inner polygons can contain lines and polygons, or only lines, so: #!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2008 Medardo Rodriguez (Merchise Group) # # This is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License (GPL) as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. # # :) def MoveDelta(target, dx, dy): for item in target: if isinstance(item[0], list):# is item a polygon? MoveDelta(item, dx, dy) # Recursive version else: assert len(item) == 2# make sure that it is a point item[0] += dx item[1] += dy if __name__ == '__main__': sample = [[[1, 2], [3, 4]], [[[7, 8], [10, 20]], [5, 6]]] print 'Original:', sample MoveDelta(sample, 10, 100) print 'Result:', sample # Regards -- http://mail.python.org/mailman/listinfo/python-list
Re: recursively change values in list of lists
On Aug 24, 9:17 am, "Carson Farmer" <[EMAIL PROTECTED]> wrote: > Dear list, > > I'm sure this is a relatively trivial problem, but I have been unable > to find any good examples/explanations on how to do this, so here > goes: > > I have multi-polygon object, which is simply a list of polygons, where > each polygon is a list of lines, where each line is a list of points. > What I would like to do, is change the x and y values of each point, > all the while keeping the structure of the lists intact. > > So in the end, the only thing that should be changed is the values, > not the lists themselves... clear as mud? > > Any hints, and/or suggestions are greatly appreciated, > > Carson I think you would be looking at: seq3= [[[0,1],[1,2]],[[3,4]]] [ [ [ setitem( seq1, i0, seq0* 2 ) for i0, seq0 in enumerate( seq1 ) ] for seq1 in seq2 ] for seq2 in seq3 ] >>> seq3= [[[0,1],[1,2]],[[3,4]]] >>> [ [ [ setitem( seq1, i0, seq0* 2 ) for i0, seq0 in enumerate( seq1 ) ] for >>> seq1 in seq2 ] for seq2 in seq3 ] [[[None, None], [None, None]], [[None, None]]] >>> seq3 [[[0, 2], [2, 4]], [[6, 8]]] -- http://mail.python.org/mailman/listinfo/python-list
Re: In-place memory manager, mmap (was: Fastest way to store ints and floats on disk)
castironpi wrote: Hi, I've got an "in-place" memory manager that uses a disk-backed memory- mapped buffer. Among its possibilities are: storing variable-length strings and structures for persistence and interprocess communication with mmap. It allocates segments of a generic buffer by length and returns an offset to the reserved block, which can then be used with struct to pack values to store. The data structure is adapted from the GNU PAVL binary tree. Allocated blocks can be cast to ctypes.Structure instances using some monkey patching, which is optional. Want to open-source it. Any interest? Just do it. That way users can come along later. Kris -- http://mail.python.org/mailman/listinfo/python-list
Re: recursively change values in list of lists
Le Sunday 24 August 2008 16:17:46 Carson Farmer, vous avez écrit : > Dear list, > > I'm sure this is a relatively trivial problem, but I have been unable > to find any good examples/explanations on how to do this, so here > goes: > > I have multi-polygon object, which is simply a list of polygons, where > each polygon is a list of lines, where each line is a list of points. > What I would like to do, is change the x and y values of each point, > all the while keeping the structure of the lists intact. > As you know the structure by advance, this is not a recusive problem : for polygon in multi : for line in polygon : for point in line : point[0] += x point[1] += y > So in the end, the only thing that should be changed is the values, > not the lists themselves... clear as mud? > > Any hints, and/or suggestions are greatly appreciated, > > > Carson > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list
Re: recursively change values in list of lists
Am Sun, 24 Aug 2008 15:17:46 +0100 schrieb Carson Farmer: > Dear list, > > I'm sure this is a relatively trivial problem, but I have been unable to > find any good examples/explanations on how to do this, so here goes: > > I have multi-polygon object, which is simply a list of polygons, where > each polygon is a list of lines, where each line is a list of points. > What I would like to do, is change the x and y values of each point, all > the while keeping the structure of the lists intact. > > So in the end, the only thing that should be changed is the values, not > the lists themselves... clear as mud? > > Any hints, and/or suggestions are greatly appreciated, > I always do something along the lines of: for (i,obj) in enumerate(list_of_objects): obj = do_something_to_obj(obj) list_of_objects[i] = obj HTH. YMMV. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: What is class method?
On Sun, Aug 24, 2008 at 4:32 AM, Hussein B <[EMAIL PROTECTED]> wrote: > I'm familiar with static method concept, but what is the class method? > how it does differ from static method? when to use it? "Class Methods" are related to the meta-class concept introduced since the first beginning of OOP but not known enough so far. If you are capable to reason (to model) using that concept, the you will need "classmethod" decorator in Python. "Static Methods" are global operations but are declared in the name-space context of a class; so, they are not strictly methods. In Python everything is an object, but functions declared in the module scope not receive the instance of the module, so they are not module methods, they are not methods, they are global functions that are in the name-space context of the module in this case. Methods always receive the instance as a special argument (usually declared as self in Python). Classes (theoretically speaking) are also objects (dual behavior). Let's be explicit: # class Test(object): def NormalMethod(self): print 'Normal:', self @staticmethod def StaticMethod(self=None): print 'Static:', self @classmethod def ClassMethod(self): print 'Class:', self test = Test() test.NormalMethod() test.StaticMethod() test.ClassMethod() # the instance "test" is coerced to it's class to call the method. # Regards -- http://mail.python.org/mailman/listinfo/python-list
Re: In-place memory manager, mmap (was: Fastest way to store ints and floats on disk)
On Aug 24, 9:52 am, Kris Kennaway <[EMAIL PROTECTED]> wrote: > castironpi wrote: > > Hi, > > > I've got an "in-place" memory manager that uses a disk-backed memory- > > mapped buffer. Among its possibilities are: storing variable-length > > strings and structures for persistence and interprocess communication > > with mmap. > > > It allocates segments of a generic buffer by length and returns an > > offset to the reserved block, which can then be used with struct to > > pack values to store. The data structure is adapted from the GNU PAVL > > binary tree. > > > Allocated blocks can be cast to ctypes.Structure instances using some > > monkey patching, which is optional. > > > Want to open-source it. Any interest? > > Just do it. That way users can come along later. > > Kris How? My website? Google Code? Too small for source forge, I think. -- http://mail.python.org/mailman/listinfo/python-list
Re: In-place memory manager, mmap (was: Fastest way to store ints and floats on disk)
source-forge places no limits and is a very good place (specific project site / releases / usage counters) -- http://mail.python.org/mailman/listinfo/python-list
IDE
i need link of latest IDE of python(GUI) -- http://mail.python.org/mailman/listinfo/python-list
Re: IDE
krishna wrote: i need link of latest IDE of python(GUI) http://wiki.python.org/moin/IntegratedDevelopmentEnvironments (is google broken today?) -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
http://matplotlib.sourceforge.net/ I'm using Python 2.4. The install looks pretty complicated for Windows. It doesn't seem like matplotlib is a module. Maybe going with the enthought edition would be easiest for you as it is a very complete set of tools all in one package. It's at http://www.enthought.com/products/epd.php These are really nice tools for scientific (and other) data analysis, and are very competitive with most professional packages. There are other bundles as well, like Sage. I've always used enthought. On the other hand, I think making tools that use these in a bundled exe might be more difficult, and if possible, might not be consistent with their license agreements, and might make for large packages. I never really looked into this. Also, with matplotlib, you might just try installing it without anything else and see how it goes. Just download the exe and double-click, or the egg file and do whatever one does with those. I bet it will work... I think it will just default to using Tk for the GUI, which you already have installed with Python, and it won't use agg (an anti-aliasing library), so your plots won't be quite as pretty. But they'll still be nice, and it will likely work. -- http://mail.python.org/mailman/listinfo/python-list
Date Comparison and Manipulation Functions?
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after 22:02:51? (24 hour day is fine) How about the date after 02/28/04 is 02/29/04, or the date after 09/30/08 is 10/01/08? How about is 03/03/04 20:10:08 after 03/07/03 14:00:00? Probably the others above will suffice. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet Web Page: -- http://mail.python.org/mailman/listinfo/python-list
Re: Date Comparison and Manipulation Functions?
"W. eWatson" <[EMAIL PROTECTED]> writes: > Are there some date and time comparison functions that would compare, say, > > Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) > Is 02/11/07 the same as 02/11/07? > > Is 14:05:18 after 22:02:51? (24 hour day is fine) > > How about the date after 02/28/04 is 02/29/04, or the date after > 09/30/08 is 10/01/08? > > How about is 03/03/04 20:10:08 after 03/07/03 14:00:00? Probably the > others above will suffice. http://docs.python.org/lib/module-datetime.html -- http://mail.python.org/mailman/listinfo/python-list
Re: In-place memory manager, mmap
castironpi wrote: On Aug 24, 9:52 am, Kris Kennaway <[EMAIL PROTECTED]> wrote: castironpi wrote: Hi, I've got an "in-place" memory manager that uses a disk-backed memory- mapped buffer. Among its possibilities are: storing variable-length strings and structures for persistence and interprocess communication with mmap. It allocates segments of a generic buffer by length and returns an offset to the reserved block, which can then be used with struct to pack values to store. The data structure is adapted from the GNU PAVL binary tree. Allocated blocks can be cast to ctypes.Structure instances using some monkey patching, which is optional. Want to open-source it. Any interest? Just do it. That way users can come along later. Kris How? My website? Google Code? Too small for source forge, I think. -- http://mail.python.org/mailman/listinfo/python-list Any of those 3 would work fine, but the last two are probably better (sourceforge hosts plenty of tiny projects) if you don't want to have to manage your server and related infrastructure yourself. Kris -- http://mail.python.org/mailman/listinfo/python-list
How to check in CGI if client disconnected
Hi, I am writing a CGI to serve files to the caller. I was wondering if there is any way to tell in my CGI if the client browser is still connected. If it is not, i want to execute some special code before exiting. Is there any way to do this? Any help on this is appreciated :) Regards, -vishal. -- http://mail.python.org/mailman/listinfo/python-list
Re: EOF
Thanks for the shutil.copyfileobj. Oddly, the EOFError didnt work though. Gabriel Genellina wrote: En Fri, 22 Aug 2008 16:53:58 -0300, Wojtek Walczak <[EMAIL PROTECTED]> escribió: On Fri, 22 Aug 2008 22:18:37 +0530, Anjanesh Lekshminarayanan wrote: Im trying to download a file from a server. But how do I detect EOF ? Whenever read() method returns empty string/list. while f1: # When to stop ? retval = f1.read() if not retval: break f2.write(retval) Those read() should be read(size) - read() tries to get the whole contents in memory. Anyway, shutil.copyfileobj already implements that logic. -- http://mail.python.org/mailman/listinfo/python-list
Re: Interrupt python thread
Group all the threads in a list and call the stop method on all of them. On Sun, Aug 24, 2008 at 1:48 AM, BlueBird <[EMAIL PROTECTED]> wrote: > Hi, > > I have a program with a master thread and several slave threads. > > Whenever an exception occurs, in the master thread or in one of the > slave threads, I would like to interrupt all the threads and the main > program. Threading API does not seem to provide a way to stop a > thread, is there anyway to achieve that ? > > The closest thing I found is thread.interrupt_main() but it's far from > perfect : > - it only allow to interrupt the main thread > - if the main thread is sleeping, it does not interrupt it (at least > on windows) > >cheers, > >Philippe > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Interrupt python thread
James Matthews wrote: Group all the threads in a list and call the stop method on all of them. what stop method? -- http://mail.python.org/mailman/listinfo/python-list
hr.rec.kladjenje,rec.pets.cats.anecdotes
hr.rec.kladjenje,rec.pets.cats.anecdotes -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports awareness in Imported modules problem
En Sun, 24 Aug 2008 07:34:41 -0300, Mohamed Yousef <[EMAIL PROTECTED]> escribió: > On Sun, Aug 24, 2008 at 9:59 AM, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >> Mohamed Yousef wrote: >> >>> why am i doing this in the first place >>> I'm in the process of a medium project where imports of modules start >>> to make a jungle and i wanted all needed imports to be in a single >>> file (namely __init__.py) >>> and then all imports are made once and other modules feel it >> >> Python doesn't use a global namespace -- importing a given module into one >> module doesn't make it visible everywhere else (and trust me, this is a very >> good thing). > why isn't it a good thing (even if optional) > consider the sitution in which a utility module is used every where > else - other modules - > you may say import it in them all , Yes. That way, when you see a name "foo" used in a module, you can look at the imports to see where it comes from. (BTW, this is why using "from module import *" is not a good idea) Having a single global namespace is a lot worse. > what i changed it's name ? go back > change all imports... this doesn't seem good Yes. How often do you change the module's name? You may use an alias if you want to be backwards compatible. > and what about package wide varailbles ? If pkgA is a package, and you define a variable foo in its __init__.py, it is available as pkgA.foo - does it count as a "package wide variable"? >>> my goal is basically making W() aware of the re module when called >>> from A >> >> to do that, add "import re" to the top of the C module. > and sys ,string.. etc add them all twice or four / n times ? Every module has its own namespace, it contains its own set of imports, unrelated to others. If you want to use the re, or sys, or string modules - import them. As F.L. has already pointed, a module is loaded from disk only the first time it is imported; subsequent imports find the module in sys.modules and do nothing. > remove one and then forget to remove one of them in a file and start > debugging ... this really doesn't look to be a good practice Why is that? Importing an otherwise unused module is usually just a performance problem - at least for well-behaving modules that don't have side effects on import. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 8: Byte Order Mark (BOM) vs coding cookie
On Sun, 24 Aug 2008 07:28:53 -0700, twyk wrote: > So is it good style to omit the BOM in UTF-8 for Python 3.0? I'd say yes because it is unnecessary with UTF-8 and it messes up the she- bang line of scripts. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check in CGI if client disconnected
En Sun, 24 Aug 2008 14:25:03 -0300, Vishal <[EMAIL PROTECTED]> escribió: >I am writing a CGI to serve files to the caller. I was wondering if > there is any way to tell in my CGI if the client browser is still > connected. If it is not, i want to execute some special code before > exiting. > >Is there any way to do this? Any help on this is appreciated :) I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: semantics of the |= operator
thanks everybody. -- http://mail.python.org/mailman/listinfo/python-list
Re: In-place memory manager, mmap
On Aug 24, 12:19 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote: > castironpi wrote: > > On Aug 24, 9:52 am, Kris Kennaway <[EMAIL PROTECTED]> wrote: > >> castironpi wrote: > >>> Hi, > >>> I've got an "in-place" memory manager that uses a disk-backed memory- > >>> mapped buffer. Among its possibilities are: storing variable-length > >>> strings and structures for persistence and interprocess communication > >>> with mmap. > >>> It allocates segments of a generic buffer by length and returns an > >>> offset to the reserved block, which can then be used with struct to > >>> pack values to store. The data structure is adapted from the GNU PAVL > >>> binary tree. > >>> Allocated blocks can be cast to ctypes.Structure instances using some > >>> monkey patching, which is optional. > >>> Want to open-source it. Any interest? > >> Just do it. That way users can come along later. > > >> Kris > > > How? My website? Google Code? Too small for source forge, I think. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Any of those 3 would work fine, but the last two are probably better > (sourceforge hosts plenty of tiny projects) if you don't want to have to > manage your server and related infrastructure yourself. > > Kris I decided on Google Code. The demo creates 'mappedtree.dat' at 3000 bytes, and allocates or frees memory blocks in it at random. There is a insert-stress test, and a concurrent read-write test too. Tested on WinXP with Python 2.5. Have a look. http://code.google.com/p/pymmapstruct/source/browse/trunk/allocbuf.py -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check in CGI if client disconnected
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote: >>I am writing a CGI to serve files to the caller. I was wondering if >> there is any way to tell in my CGI if the client browser is still >> connected. If it is not, i want to execute some special code before >> exiting. >> >>Is there any way to do this? Any help on this is appreciated :) > > I don't think so. A CGI script runs once per request, and exits. The server > may find that client disconnected, but that may happen after the script > finished. I am not a web developer, but I think that the only way is to set a timeout on server side. You can't be sure that the client disconnected, but you can stop CGI script if there's no action on client side for too long. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list
Python String Immutability Broken!
South Africa. Sunday 24th August 2008. Our South African correspondent, Waffling Swiftly, reports the discovery of a corpse in the local cyberspace. It is reputed to belong to a programmer who was flayed alive by the C.L.P. group, because he had violated the immutability of a python string. Rumour has it that the attack was led, and the killing blow struck, by the "KILL GIL" girl who left her lair on Irmen "Mr. Pyro"'s blog at http://www.razorvine.net/frog/user/irmen/article/2005-02-13/45 in order to perform the hit, using her katana. When asked to comment, the BDFL shrugged and said: The guy had it coming. He was the architect of his own misfortune. Python strings _are_ immutable. Here is the evidence: [EMAIL PROTECTED]:/tmp/disk/ebox/iotest/lib# python Python 2.5.2 (r252:60911, Mar 1 2008, 13:52:45) [GCC 4.2.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s = 'The quick brown fox jumps over the lazy dog and now is the time!' >>> s 'The quick brown fox jumps over the lazy dog and now is the time!' >>> import ctypes as c >>> io = c.cdll.LoadLibrary('./lib_gpio.a') >>> io.io_en() 0 >>> io.read_write(s,len(s)) 255 >>> s '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff' >>>g = 'boo' >>> io.read_write(g,len(g)) 255 >>> g '\xff\xff\xff' >>> And here is the incriminating code: WARNING: Don't do this at home. It does low level i/o and unless you run it on a DMP Vortex processor, it might turn your printer into a pumpkin, or something. YOU HAVE BEEN WARNED! #include #include #include #include /* We define our read and write routines */ #define write_port(a,b) outb(b,a) #define read_port(a) inb(a) /* Then we hard code the port numbers we need */ #define data_0 (0x78) #define data_1 (0x79) #define data_2 (0x7a) #define dir_0 (0x98) #define dir_1 (0x99) #define dir_2 (0x9a) /* Here we organise permission to use the ports*/ int io_en() { int rv = 0; rv = iopl(3); return rv; } /* Then we make some dumb i/o routines for testing */ /* first we make outputs */ unsigned char put_0 (char x) { write_port (dir_0, 0xff); write_port (data_0, x); return 0x00; } unsigned char put_1 (char x) { write_port (dir_1, 0xff); write_port (data_1, x); return 0x00; } unsigned char put_2 (char x) { write_port (dir_2, 0xff); write_port (data_2, x); return 0x00; } /* Then we make inputs */ unsigned char rval = 0x00; unsigned char get_0 () { write_port (dir_0, 0x00); rval = read_port(data_0) & 0xff; return rval; } unsigned char get_1 () { write_port (dir_1, 0x00); rval = read_port(data_1) & 0xff; return rval; } unsigned char get_2 () { write_port (dir_2, 0x00); rval = read_port(data_2) & 0xff; return rval; } /* This routine outputs and inputs a symmetric block of bytes, writing the outputs out and replacing them by the corresponding inputs */ unsigned char read_write (unsigned char *outputs, int len) { int i = 0; char rv; while (i < len) { rv = put_1(i); /* put out the addy */ rv = put_0(outputs[i]); /* put out the char */ rv = put_2('\x03'); /* make a write strobe */ rv = put_2('\x02'); rv = put_2('\x03'); rv = get_0(); /* turn the bus around */ rv = put_2('\x05'); /* make a read strobe */ rv = put_2('\x04'); outputs[i] = get_0(); /* read the char */ rv = put_2('\x05'); /* 3-state bus again */ i++; } return *outputs; } The man's dying words were supposed to be: You often see this pattern of inputs replacing outputs in DSP serial port code. I suppose I should have used array.array... aaahhrgh...!! Flowers, comments, pitfalls, advice and money are welcome! - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python String Immutability Broken!
In article <[EMAIL PROTECTED]>, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > It is reputed to belong to a programmer who was flayed alive Reminds me of that great old song from "Saturday Night Hacker": Oh, oh, oh, oh. Flaying alive, flaying alive. Oh, oh, oh, oh. Flaying ali-i-i-i-i-ive! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check in CGI if client disconnected
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <[EMAIL PROTECTED]> escribió: > On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote: >>>I am writing a CGI to serve files to the caller. I was wondering if >>> there is any way to tell in my CGI if the client browser is still >>> connected. If it is not, i want to execute some special code before >>> exiting. >>> >>>Is there any way to do this? Any help on this is appreciated :) >> >> I don't think so. A CGI script runs once per request, and exits. The server >> may find that client disconnected, but that may happen after the script >> finished. > > I am not a web developer, but I think that the only way is to > set a timeout on server side. You can't be sure that the client > disconnected, but you can stop CGI script if there's no > action on client side for too long. Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure). If processing takes so much time, it's better to assign it a "ticket" - the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Interrupt python thread
def __stop(self): self.__block.acquire() self.__stopped = True self.__block.notifyAll() self.__block.release() On Sun, Aug 24, 2008 at 11:59 AM, Fredrik Lundh <[EMAIL PROTECTED]>wrote: > James Matthews wrote: > > Group all the threads in a list and call the stop method on all of them. >> > > what stop method? > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
On Aug 23, 10:11 am, Scott David Daniels <[EMAIL PROTECTED]> wrote: > W. eWatson wrote: > > ... > > I'm working on this now, but my knowledge of python needs refreshing. > > Right now I have a file of all the az,el data I've collected, and I'd > > like to open it with Python for XP. However, Python doesn't like this: > > > junkfile = open('c:\tmp\junkpythonfile','w') > > > I get > > junkfile = open('c:\tmp\junkpythonfile','w') > > IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile' > > > This problematic segment is just a hack of a similar statement which has > > the same problem and a much longer path. I suspect the problem is with > > the back slash. > > A standard windows error. note that '\t' is a tab, and I doubt you have > a directory named . Get in the habit of _always_ using: > junkfile = open(r'c:\tmp\junkpythonfile','w') > or > junkfile = open('c:\\tmp\\junkpythonfile','w') > for file names. > > --Scott David Daniels > [EMAIL PROTECTED] Avoid backslashes whenever possible. junkfile = open('c:/tmp/junkpythonfile','w') -- http://mail.python.org/mailman/listinfo/python-list
Re: What is class method?
On Sun, 24 Aug 2008 11:09:46 +0200, Hrvoje Niksic wrote: > Hussein B <[EMAIL PROTECTED]> writes: > >> Hi, >> I'm familiar with static method concept, but what is the class method? >> how it does differ from static method? when to use it? -- >> class M: >> def method(cls, x): >> pass >> >> method = classmethod(method) > > Use it when your method needs to know what class it is called from. Ordinary methods know what class they are called from, because instances know what class they belong to: def method(self, *args): print self.__class__ You use class methods when you DON'T need or want to know what instance it is being called from, but you DO need to know what class it is called from: @classmethod def cmethod(cls, *args): print cls Why is this useful? Consider the dict method "fromkeys". You can call it from any dictionary, but it doesn't care which dict you call it from, only that it is being called from a dict: >>> {}.fromkeys([1, 2, 3]) {1: None, 2: None, 3: None} >>> {'monkey': 42}.fromkeys([1, 2, 3]) {1: None, 2: None, 3: None} Any method that behaves like dict.fromkeys() is an excellent candidate for classmethod. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to set/get an object property
On Sun, 24 Aug 2008 12:28:53 +0200, Peter Otten wrote: > Hussein B wrote: > >> I noted that Python encourage the usage of: -- >> obj.prop = data >> x = obj.prop >> -- >> to set/get an object's property value. What if I want to run some logic >> upon setting/getting a property? What is Python preferred method to do >> so (using the new feature 'property')? >> I don't think __getattr__ and __setattr__ are practical (I have to code >> the property name into them). > > Hussein, I don't think you'll learn much from asking these abstract > questions. At some point you have to get your hands dirty and write > actual code to get a feel for the language. > > For example, it will then become obvious for you that property works > best for individual attributes while __getattr__ and friends are more > convenient if you want to treat multiple attributes the same way, > attributes whose names may not even be known until runtime (think > delegation). I think you are misunderstanding Hussein's question. I believe that he is using "property" to refer to what we would call an attribute. Naturally I could be wrong, but this is how I interpret his question. I think the actual answer to his question is that properties are the preferred way to "run some logic upon setting/getting" an attribute, that is, to implement getters and setters. Hussein, the Java habit of writing setters and getters for everything isn't considered good practice in Python, but if you need them, that's exactly what the property() function is for. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
castironpi <[EMAIL PROTECTED]> wrote: > Python isn't as clever as you think. It's a language. Yet another non-sequitur response from you. At which point in my post did I make any such claims about Python's 'cleverness'? > Do you want a > link to clever code? Not if you wrote it or find it clever, no. To quote Kernighan: "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." When the code in question is one of the abstract monstrosities you regularly post here - often in response to _new python users_ asking _basic_ questions that _don't require metaclass solutions_ - I've repeatedly found the cost in interpreting it is just never worth the time and effort required. > I like to encourage creativity. Then why do you seem to stymie it? Care to go back through the responses to your posts and tally up the "thanks, that makes sense!" replies to the "I don't get what you mean here" ones? If you're seriously attempting to educate, you're failing. If you're trying to show how blazingly clever you are, you're failing at that, too. When people seem to generally consider you a markov chainer, that - should- be a sign to work on the clarity of your communication. -- http://mail.python.org/mailman/listinfo/python-list
RE: exception handling in complex Python programs
Lie wrote: > Ah... now I understand what the Zen is talking about when it said: > "Now is better then never, although never is often better than *right* > now." If you don't have all the necessary resources to fix an > exception right now, don't try to fix it, instead let it propagate, > and allow it to be handled in a level where there is enough > information how to fix it. Well, I believe the original intent was more along the lines of adding features, etc to Python, but it's apropos here as well. > I think we should change except: into expect:, it would confuse less, > would it? It signifies that the program expects so and so kinds of > exceptional situations. Whilst the connotations are good, and I think create the right mindset, it ain't gonna happen. Cheers, Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list
Hide Console
When I use py2exe to convert Python script to executable Windows programs I always have a black console pop up behind my program. If i run the script before i convert it with py2exe it don't have the console because i save the script ending with .pyw instead of .py. Is there a way to get rid or hide this console once i've turned it into a executable windows program? Thanks you Kevin McKinley -- http://mail.python.org/mailman/listinfo/python-list
Re: Hide Console
On Aug 25, 10:59 am, Kevin McKinley <[EMAIL PROTECTED]> wrote: > When I use py2exe to convert Python script to executable Windows programs I > always have a black console pop up behind my program. If i run the script > before i convert it with py2exe it don't have the console because i save the > script ending with .pyw instead of .py. Is there a way to get rid or hide > this console once i've turned it into a executable windows program? You probably have a line in your setup.py similar to: setup(console=['app.py']) Change the 'console' to 'window' as such: setup(window=['app.py']) I -think- that should take care of it, but it's been a while since I last used py2exe. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python String Immutability Broken!
On Aug 24, 8:49 pm, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > (a lot of stuff related to using a string with a C library via ctypes) Very entertaining. But let me get this straight: Are you just complaining that if you pass a string to an arbitrary C function using ctypes, that that arbitrary function can modify the string? Because if you are, then I think you share a great deal of responsibility for the death of that string -- sending the poor thing to its grave through some unknown C function. What would you have ctypes do instead? -- http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
On Aug 24, 7:43 pm, alex23 <[EMAIL PROTECTED]> wrote: > castironpi <[EMAIL PROTECTED]> wrote: > > Python isn't as clever as you think. It's a language. > > Yet another non-sequitur response from you. At which point in my post > did I make any such claims about Python's 'cleverness'? > > > Do you want a > > link to clever code? > > Not if you wrote it or find it clever, no. > > To quote Kernighan: "Debugging is twice as hard as writing the code in > the first place. Therefore, if you write the code as cleverly as > possible, you are, by definition, not smart enough to debug it." > > When the code in question is one of the abstract monstrosities you > regularly post here - often in response to _new python users_ asking > _basic_ questions that _don't require metaclass solutions_ - I've > repeatedly found the cost in interpreting it is just never worth the > time and effort required. > > > I like to encourage creativity. > > Then why do you seem to stymie it? Care to go back through the > responses to your posts and tally up the "thanks, that makes sense!" > replies to the "I don't get what you mean here" ones? > > If you're seriously attempting to educate, you're failing. If you're > trying to show how blazingly clever you are, you're failing at that, > too. > > When people seem to generally consider you a markov chainer, that - > should- be a sign to work on the clarity of your communication. I'm baffled. I don't understand what you write. I think someone in my shoes would be justified in dismissing it as either malicious or a miscommunication. My typical response is, take something I've said in context, and show how it fulfills the criteria you describe. For instance, "I won't like it if you do" and "I won't think it's clever if you do" aren't consistent belief structures, they're fight structures. You have made such claims. In the post above, I make two claims, ask two questions, and encourage a brainstorm. I don't see how what you say applies to it. I am willing to change the way I communicate. I want to communicate effectively. But, until someone takes something I want to say, and says it the right way, I can't learn how. So I wait and write Python, and share my frustration with my peers. Lastly, in the syllogism you propose, "not smart enough to debug it", you equate maximally clever writing with maximally clever debugging, which is clearly wrong. They are distinct; someone could be better at either one than the other. And besides, your quoted premise "twice as hard" is assumed, not proven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Date Comparison and Manipulation Functions?
check out Pyfdate: http://www.ferg.org/pyfdate from pyfdate import * t = Time().add(hours=14) print "It is now", t.wdt datestring1 = "2005/10/05" #year,month,day datestring2 = "2002/09/22" #year,month,day datestring3 = "2007/11/11" #year,month,day year,month,day = numsplit(datestring1) # split into integers t1 = Time(year,month,day) for datestring in (datestring2,datestring1,datestring3): year,month,day = numsplit(datestring) t2 = Time(year,month,day) if t1 > t2: print t1.isodate, "is later than ", t2.isodate elif t1 == t2: print t1.isodate, "is the same as ", t2.isodate elif t1 < t2: print t1.isodate, "is earlier than", t2.isodate print t1 = Time(2000,2,28) print "The date after", t1.d, "is", t1.plus(day=1).d t1 = Time(2001,2,28) print "The date after", t1.d, "is", t1.plus(day=1).d t1 = Time(2004,2,28) print "The date after", t1.d, "is", t1.plus(day=1).d print datestring1 = "2005/10/05 20:10:08" datestring2 = "2005/10/05 20:10:06" datestring3 = "2005/10/05 20:10:09" t1 = Time(*numsplit(datestring1)) for datestring in (datestring2,datestring1,datestring3): t2 = Time(*numsplit(datestring)) if t1 > t2: print t1.d, t1.civiltime2, "is later than ", t2.d, t2.civiltime2 elif t1 == t2: print t1.d, t1.civiltime2, "is the same as ", t2.d, t2.civiltime2 elif t1 < t2: print t1.d, t1.civiltime2, "is earlier than", t2.d, t2.civiltime2 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to search the Python manuals
BJörn Lindqvist wrote: 2008/8/22 Terry Reedy <[EMAIL PROTECTED]>: [snip] On the left, click [+] for Language Reference (3.0: The Python language reference). "Language Reference (for language lawyers)" Language Lawyer? That's almost as worser than Grammar Nazi, no wonder no one is finding anything there. That unfortunate joke is gone from the new 2.6/3.0 manuals. I and others have spend much time working to make the manuals more accurate and readable. -- http://mail.python.org/mailman/listinfo/python-list
Books about Python.
I'm up to write a 20-30 research paper for my computer science course, and I was considering choosing to do mine on Python. I was curious if anybody knows of any good books about python they could recommend that have more of a technical view rather than a Teach-yourself-in-24-hours type. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
On Aug 25, 12:42 pm, castironpi <[EMAIL PROTECTED]> wrote: > I'm baffled. I don't understand what you write. Which is pretty much how I feel about -all- of your posts. > I think someone in > my shoes would be justified in dismissing it as either malicious or a > miscommunication. No, it's frustration at the sharp decrease in signal:noise that this newsgroup has undertaken since your arrival. > My typical response is, take something I've said in > context, and show how it fulfills the criteria you describe. Generally, it's -extremely difficult- understanding your context, for starters. But how about this, your code snippet from this very thread, your -first- of two seemingly independent replies to the original post: > def _getbalance( self ): >return self._tree.geti( > self.where+ self.lookup[ 'balance' ] ) > > def _getparent( self ): >return self._tree.getI( > self.where+ self.lookup[ 'parent' ] ) > > Where 'balance' and 'parent' could both come from something generic: > > balance= property( tree_lookup( 'balance' ) ) > parent= property( tree_lookup( 'parent' ) ) In your 'example', you reference one marked-as-implementation attribute, two unspecified attributes, one unspecified method and one unspecified function. That you refer to one function as both 'geti' and 'getI' leads me to believe this -isn't- workable code and you've just re-keyed this in without testing. I've also -no- idea what you're trying to demonstrate here. It's not clear nor obvious, and I can't see how your _getwhatever methods tie in with the property definition. > For instance, "I won't like it if you do" and "I won't think it's > clever if you do" aren't consistent belief structures, they're fight > structures. You have made such claims. No, what I've stated is I've yet to see -any- code samples that you've provided be of any real, clear use to -anyone-. This isn't a 'fight structure', this is an opinion formed by the overwhelming amount of evidence you keep contributing to this group. > In the post above, I make two claims, ask two questions, and encourage > a brainstorm. I don't see how what you say applies to it. What you said was: "When brainstorming, don't restrict yourself to Python syntax-- make something up, and we'll write Python." What I'm contesting is your ability to write Python. Furthermore, people -aren't- posting questions to the "castironpi hour", they're asking questions to help further their understanding of Python, not to give you further opportunity to emphasise your misunderstanding of it. Suggesting they 'brainstorm' without any understanding of the language itself and that you'll somehow magically generate Python code for them is, based on what you've written here, laughable. > I am willing to change the way I communicate. I want to communicate > effectively. But, until someone takes something I want to say, and > says it the right way, I can't learn how. So I wait and write Python, > and share my frustration with my peers. Given how many people have publicly killfiled you on this group, I'm not sure who you consider to be your 'peers'. There was a -lot- of initial frustration at your post, along with even more dismissal of it as the output of a poorly written AI experiment. You're -failing- the Turing test. If that isn't telling you something is wrong with your communication style, I don't really know what will. > Lastly, in the syllogism you propose, "not smart enough to debug it", > you equate maximally clever writing with maximally clever debugging, > which is clearly wrong. They are distinct; someone could be better at > either one than the other. And besides, your quoted premise "twice as > hard" is assumed, not proven. Assumed by someone whose programming knowledge I have a -lot- more respect for than your's, mostly because Kernighan's is -more than amply demonstrated-. Which leads me to reiterate my original statement, only framing it now as a question: what -real world- applications or systems have you worked on...in -any- language? I find it difficult to believe you've ever worked on any, or even more pointedly, had to work on -someone else's real world code-. Because the sample code fragments you post, when not broken, at best seem to relate to pointless wankery on your behalf, without any practical application whatsoever, and at worst carry deep-seated misunderstandings about how Python works. -- http://mail.python.org/mailman/listinfo/python-list
Python cx_Oracle and Apache
Hi, I am trying to write a cgi program which would be executed on browser with Apache server installed. The program would make a connection to a database using cx_Oracle module and display results on page. The code is working fine on the command line but when executing it on the browser i get the famouse "Premature end of script headers" error. I went ahead and found the problem occuring exactly when the code is asking for a connection to the database. I am attaching the program for reference. Let me know if there is anything I need to make changes to apache or any other way to overcome this issue. #!/apollo/bin/env -e TestDatabaseTraceDashboard python import cgi import sys, os #import cgitb;cgitb.enable() #os.environ[ 'ORACLE_HOME' ] = '/opt/app/oracle/product/10.2.0.2/ client' #if os.environ.has_key( 'LD_LIBRARY_PATH' ): # ld_library_path = os.environ[ 'LD_LIBRARY_PATH' ] # os.environ[ 'LD_LIBRARY_PATH' ] = '%s/lib:%s' % ( os.environ[ 'ORACLE_HOME' ], ld_library_path ) #os.environ['BRAZIL_CONFIG']="--root=/apollo/env/ TestDatabaseTraceDashboard --user=oracle" try: import cx_Oracle import cx_Oracle_Amazon except ImportError, e: #sys.stdout.write( "Import error: %s" % ( e ) ) #sys.argv[0] = '/opt/app/oracle/admin/scripts/monitor-manager' def test_dbconnect(): connection=cx_Oracle.Connection('suvidhak_admin','database','dcrno1') cur=connection.cursor() cur.execute('select shipment_id from pending_customer_shipments where rownum < 10') return cur cursor = test_dbconnect() def generate_output(): print '' generate_output() Thanks, Raja. -- http://mail.python.org/mailman/listinfo/python-list
swig double[], under the gun and need help
I'm using python 2.4 under linux (centos 5.1). I need to pass an array of doubles to a c function but am getting an error, shown near the bottom of this post. my swig interface file looks like this * File: rug520.i */ %module rug520 %include "typemaps.i" %include "carrays.i" %array_class(double, doubleArray); %{ #define SWIG_FILE_WITH_INIT #include "rug520.h" extern double[] nCmiArray; %} %apply int *OUTPUT { char *sRugHier, char * sRugMax, int * iRugHier, int * iRugMax, double * nCmiValueHier, double * nCmiValueMax, int * iAdlSum, int * iCpsCode, char * sRugsVersion, char * sDllVersion, int * iError }; int RugCalc( char * sMdsRecord, char * sRehabType, char * sModel, int iQuarterlyFlag, double nCmiArray[], char * sRugHier, char * sRugMax, int * iRugHier, int * iRugMax, double * nCmiValueHier, double * nCmiValueMax, int * iAdlSum, int * iCpsCode, char * sRugsVersion, char * sDllVersion, int * iError ); -- my test code looks like this: import sys, os, rug520 cmi=[0.0] *59 def getrug(mds): results = rug520.RugCalc(mds, 'mcare', '34', 0, cmi) print 'results', results datafile = open('mdsdata.txt') for d in datafile: if d[0]=='B': getrug(d) I get this error message File "testrug520.py", line 11, in ? getrug(d) File "testrug520.py", line 5, in getrug results = rug520.RugCalc(mds, 'mcare', '34', 0, cmi) TypeError: in method 'RugCalc', argument 5 of type 'double []' -- I'm guessing that I am not passing a double array to the c code. I cannot change the c code due to politics. I could write a c "wrapper" if I had to, but would rather stay within python or the swig interface definitions if possible/practical. I'm not much of a c programmer; mostly java and python with a little c++. I've looked in the swig docs and tried google, but either have not found it or just don't understand what they are telling me here. --- The information contained in this message may be privileged and / or confidential and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to this message and deleting the material from any computer. --- -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 8: Byte Order Mark (BOM) vs coding cookie
twyk wrote: PEP 8 says ... Files using ASCII (or UTF-8, for Python 3.0) should not have a coding cookie. What about a BOM (Byte Order Mark)? Per Wikipedia ... http://en.wikipedia.org/wiki/Byte-order_mark#endnote_UTF-8) 'In UTF-8, this is not really a "byte order" mark. It identifies the text as UTF-8 but doesn't say anything about the byte order, because UTF-8 does not have byte order issues.' So is it good style to omit the BOM in UTF-8 for Python 3.0? According to Unicode manual, yes. http://www.unicode.org/versions/Unicode5.0.0/ch02.pdf The endian order entry for UTF-8 in Table 2-4 is marked N/A because UTF-8 code units are 8 bits in size, and the usual machine issues of endian order for larger code units do not apply. The serialized order of the bytes must not depart from the order defined by the UTF- 8 encoding form. Use of a BOM is neither required nor recommended for UTF-8, but may be encountered in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature. See the “Byte Order Mark” subsection in Section 16.8, Specials, for more information. Since Ascii files *are*, by intentional design, UTF-8 files, and since Python assumes Ascii/UTF-8 as the default, in the absence of a coding cookie, it does not need the signature. -- http://mail.python.org/mailman/listinfo/python-list
emacs-mode for python, run the interpreter doesnt work
how do I run the interpreter In emacs? pythonmode works but I cant start the interpreter. do I need to add it to my load-path? what should I add exactly then? python.exe or pythonw.exe? -- http://mail.python.org/mailman/listinfo/python-list
Re: Books about Python.
On Aug 24, 8:32 pm, [EMAIL PROTECTED] wrote: > I'm up to write a 20-30 research paper for my computer science course, > and I was considering choosing to do mine on Python. I was curious if > anybody knows of any good books about python they could recommend that > have more of a technical view rather than a Teach-yourself-in-24-hours > type. > > Thanks Well here's one that cover just about everything(As you can tell from the title) But I'm not sure if it's exactly what you are looking for. http://www.amazon.com/exec/obidos/ASIN/007212718X/bigwebmasters-20 -- http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
En Mon, 25 Aug 2008 00:41:42 -0300, alex23 <[EMAIL PROTECTED]> escribió: > On Aug 25, 12:42 pm, castironpi <[EMAIL PROTECTED]> wrote: >> I'm baffled. I don't understand what you write. > Which is pretty much how I feel about -all- of your posts. May I ask both of you to continue this in private? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list