Re: Windows, IDLE, __doc_, other
* W. eWatson: When I use numpy.__doc__ in IDLE under Win XP, I get a heap of words without reasonable line breaks. "\nNumPy\n=\n\nProvides\n 1. An array object of arbitrary homogeneous items\n 2. Fast mathematical operations over arrays\n 3. Linear Algebra, Fourier Transforms, Random Number ... Is there a way to get this formated properly. print( numpy.__doc__ ) (For Python 2.x you can and best should leave out the parenthesis) If I use dir(numpy), I get yet a very long list that starts as: ['ALLOW_THREADS', 'BUFSIZE', 'CLIP', 'DataSource', 'ERR_CALL', 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'False_', 'Inf', 'Infinity', 'MAXDIMS', 'MachAr', 'NAN', 'NINF', 'NZERO', 'NaN', 'PINF', 'PZERO', 'PackageLoader', 'RAISE', 'RankWarning', 'SHIFT_DIVIDEBYZERO', 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'ScalarType', 'Tester', 'True_', 'UFUNC_BUFSIZE_DEFAULT' ... I see this might be a dictionary. What can I do to make it more readable or useful, or is that it? Is there a more abc as in Linux? Something like (off the cuff, fix if eroRs!) for name in dir[numpy]: if name.startswith( "_" ): pass else: doc_lines = getattr( numpy, name ).__doc__.split() print( format( "{0:25} {1}".format( name, doc_lines[0] ) ) Should ideally work whether you use Python 2.x or 3.x. But as mentioned I just typed that in so there may be eroRs. It the IDLE shell, it's not possible to retrieve lines entered earlier without copying them. Is there an edit facility? I suggest you download a programmers' editor (like Notepad++ or PsPad) for programming work and use the basic Python interpreter for interactive work. The basic interpreter lives in a standard Window console window where you can use up and down arrow keys, F8 completion, F7 for list of earlier commands, etc (as documented by the doskey command in the Windows command interpreter). Just forget IDLE in windows: while Windows console windows are something from the middle ages, IDLE seems to stem from a period before that! Cheers & hth., - Alf PS: Shameless plug: take a look at http://tinyurl.com/programmingbookP3>, it's for Windows. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mails & encoding
En Sun, 20 Dec 2009 07:46:02 -0300, Lord Eldritch escribió: I have a CGI written in Python to process a form a read/write a text file (a minimal database). It runs in a Linux box with and it looks all the encoding is UTF8. [...] - Related to the former one: the CGI sends an email with stress marks and other characters. I can read it with out any problem in my Kmail client because it detects the encoding. But I saw that most of the users are gonna read it in a webmail service where the characters (UTF8) are not recognized. Can I force a encoding when I send an email? kind of: mail(adress,'My title', mytext.encode'iso9865') Yes, you can, and you should. Make sure the Content-Type (and probably Content-Transfer-Encoding too) header fields are correct. How to set them, depends on how you build the email to be sent (and the Python version in use). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: logging module bug ?
En Sat, 19 Dec 2009 00:18:26 -0300, Peter escribió: This was somehow unexpected for me, since in a module using logger.py, I could use either import: from mylogger import logger # without package name or from of.mylogger import logger # with package name but this does not seem to work for the class specification in the config file (only the former works). Then you have a big problem with the Python search path (sys.path): you should *not* have two different (absolute) ways to refer to the same module, ever. If "of" is a package, it should not be listed in sys.path -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I get the target platform info of a dll with Python 3.1.1?
En Mon, 14 Dec 2009 07:25:45 -0300, W00D00 escribió: On dec. 12, 03:18, "Gabriel Genellina" wrote: En Fri, 11 Dec 2009 16:39:37 -0300, Isti escribió: > I have manydllfiles and I would like to select them into two > different folders (PC and PPC). For this I need to know the target > platform of thedllfile or any other details about its platform. Look at sys.platform and the platform module. The platform module gives you information about the platform where you are running on with your script and not about the not loaded dll(s). Sorry, I misunderstood you. (completely unrelated to your problem: see PEP8 at http://www.python.org/dev/peps/pep-0008/ ) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variables static by default?
En Sun, 20 Dec 2009 01:16:16 -0300, Steven D'Aprano escribió: On Sun, 20 Dec 2009 11:44:11 +1100, Lie Ryan wrote: In python, 'class variable' is a variable that belongs to a class; not to the instance and is shared by all instance that belong to the class. Surely, since string variables are strings, and float variables are floats, and bool variables are bools, and module variables are modules, a class variable will be a class and an instance variable will be an instance? In contrast, 'instance variable' belongs to the instance, and each instance can make their instance variables refers to different objects than the other instances. The usual term used in Python is "class attribute" and "instance attribute" for the named fields of a class or instance. I agree with your interpretation of "class variable", but you'll have to rewrite parts of the official Python documentation so it becomes consistent with it. The phrase "class variable" appears about 30 times, always meaning "class attribute"; four of them in the Language Reference, section "Class definitions", where the OP's issue is discussed: "Programmer’s note: Variables defined in the class definition are class variables; they are shared by all instances. To create instance variables, they can be set in a method with self.name = value. Both class and instance variables are accessible through the notation “self.name“, and an instance variable hides a class variable with the same name when accessed in this way. Class variables can be used as defaults for instance variables, but using mutable values there can lead to unexpected results. For new-style classes, descriptors can be used to create instance variables with different implementation details." http://docs.python.org/reference/compound_stmts.html#class-definitions -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: how do I set a Python installation as the default under windows ?
On 12/20/2009 1:35 AM, Stef Mientki wrote: Steve Holden wrote: Stef Mientki wrote: hello, I just upgraded from Python 2.5 to 2.6. Most of the things work, but I'm struggling with one issue, when I start Python in a command window, it still uses Python 2.5. Is there a way to get Python 2.6 as my default Python environment ? thanks, Stef Mientki It's a matter of replacing C:\Python25 with C:\Python26 in your PATH environment variable, which is what the Windows command processor uses to fined executable programs. Thanks Steve, that works exactly as you say. Additionally if you're using ActivePython, you do not even have to fiddle with PATH because: 1) C:\PythonXY (and %APPDATA%\Python\Scripts) is automatically added to %PATH%. 2) "python.exe" is also available as "python26.exe", so you can simply type "python26" in the console to get Python 2.6 (if another version of ActivePython/Python is already installed). -srid -- http://mail.python.org/mailman/listinfo/python-list
Re: Live Video Capture using Python
Also try.. http://www.unixuser.org/~euske/python/vnc2flv/index.html On Mon, 21 Dec 2009 11:15:32 +0530, Banibrata Dutta wrote: > Have you searched the archives of this list ? I remember seeing a related > discussion 5-6 months back. > > On Mon, Dec 21, 2009 at 2:35 AM, aditya shukla > wrote: > >> Hello Guys, >> >> I am trying to capture images from a live broadcast of a "cricket match" >> or >> say any video using python. I can see the video in the browser.My aim is >> to >> capture the video at any moment and create an images.Searching on google >> turns up http://videocapture.sourceforge.net/ .I am not sure if this >> would be help here.I would appreciate if someone points me in the right >> direction. >> >> >> Thanks >> >> Aditya >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> -- http://mail.python.org/mailman/listinfo/python-list
Re: Live Video Capture using Python
Have you searched the archives of this list ? I remember seeing a related discussion 5-6 months back. On Mon, Dec 21, 2009 at 2:35 AM, aditya shukla wrote: > Hello Guys, > > I am trying to capture images from a live broadcast of a "cricket match" or > say any video using python. I can see the video in the browser.My aim is to > capture the video at any moment and create an images.Searching on google > turns up http://videocapture.sourceforge.net/ .I am not sure if this > would be help here.I would appreciate if someone points me in the right > direction. > > > Thanks > > Aditya > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- regards, Banibrata http://www.linkedin.com/in/bdutta -- http://mail.python.org/mailman/listinfo/python-list
Re: The fun of Python
a...@pythoncraft.com (Aahz) writes: > I never called myself a programmer before I learned Python because I > didn't really like it. It took Python to make me realize that > programming *could* be fun, or at least not annoying enough to keep me > from making a career of programming. +1 QOTW -- \ “Two hands working can do more than a thousand clasped in | `\ prayer.” —Anonymous | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
The fun of Python (was Re: When will Python 3 be fully deployed)
In article , Roy Smith wrote: >In article , a...@pythoncraft.com (Aahz) >wrote: >> >> -- >> Looking back over the years, after I learned Python I realized that I >> never really had enjoyed programming before. > >That's a sad commentary. Python is fun to use, but surely there are other >ways you can enjoy programming? Not really. I've been programming more than thirty years, and the closest I came previously to enjoying programming was Turbo Pascal, and even that has too much tedium and lack of brain-fit. Before Turbo Pascal, there was BASIC on an HP-1000. Afterward came HP-41, Ada, FORTRAN, Paradox PAL, C, Perl, and there must be some others I'm forgetting. Thankfully, I didn't learn Java until after I'd been programming in Python for a while. (And arguably I still haven't learned Java despite writing a PGP encryption wrapper around BouncyCastle.) Programming is difficult to begin with, and everything other than Python just gets in my way. To be fair, my quote isn't entirely honest: I never called myself a programmer before I learned Python because I didn't really like it. It took Python to make me realize that programming *could* be fun, or at least not annoying enough to keep me from making a career of programming. -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ Looking back over the years, after I learned Python I realized that I never really had enjoyed programming before. -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On Dec 20, 2009, at 17:41 , Peter Pearson wrote: > On Sun, 20 Dec 2009 07:26:03 +1100, Lie Ryan wrote: >> On 12/20/2009 4:02 AM, Carl Johan Rehn wrote: >> >> Parallel PRNGs are an unsolved problem in computer science. >>> >>> Thanks again for sharing your knowledge. I had no idea. This means >>> that if I want to speed up my application I have to go for the fastest >>> random generator and focus on other parts of my code that can be >>> vectorized. >> >> If you don't care about "repeatability" (which is already extremely >> difficult in parallel processing even without random number generators), >> you can just start two PRNG at two distinct states (and probably from >> two different algorithms) and they will each spews out two independent >> streams of random numbers. What was "unsolved" was the "pseudo-" part of >> the random number generation, which guarantee perfect replayability in >> all conditions. > > Why not use a good cipher, such as AES, to generate a pseudorandom > bit stream by encrypting successive integers? Isn't the Fortuna PRNG based around that approximate concept? - Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Multithreaded python program freezes
On 20Dec2009 17:36, Andreas R�sdal wrote: | I have some problems with a http proxy which is implemented | in Python 2.6. A few times a day, the proxy begins using 100% CPU | and doesn't work any more. | | I have created a thread dump when the problem occurs here: | http://www.pvv.ntnu.no/~andrearo/thread-dump.html | | This is a thread dump during normal operation: | http://www.pvv.ntnu.no/~andrearo/thread-dump-normal.html These two URLs don't work for me. [...] | Any advice on why this Python program appears to freeze? Is there anything | more I can do to find out why this problem occurs? Sounds like a livelock: http://en.wikipedia.org/wiki/Deadlock#Livelock or busy lock. Can you find out which bits of your program are busy? Are there places in your code that loop, polling for data, instead of using blocking I/O. With a network proxy, a typical place that might happen is a loop testing select() (or its poll-like friends) with a short or zero timeout on inactive file handles. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ No electrons were harmed in the production of this message. - Dr. P. Gensheimer -- http://mail.python.org/mailman/listinfo/python-list
Re: converting string to a date format
tekion writes: > I have this string date format: 24/Nov/2009:10:39:03 -0500 and would > like to convert it to a date format of "2009-11-24 10:39:03". This should, ideally, consist of two separate operations: * parse the string, using a specific format, to create a ‘datetime’ object * create a string representation of the datetime using your preferred string format > At the moment I am reading datetime module trying to find out if I > could do it with datetime module. Unfortunately, the manipulation of time data has historically been a bit messy in the Python standard library; the functionality for round-trip conversion of strings and datetime values involves both the ‘datetime’ and ‘time’ modules. If you have Python 2.6 or greater, you can perform the above steps using http://docs.python.org/library/datetime.html#datetime.datetime.strptime> to parse the string to a ‘datetime’ object, and get a string from the http://docs.python.org/library/datetime.html#datetime.datetime.strftime> method of that object. If you have an earlier Python, you don't have ‘datetime.strptime’. So you'll need to follow the hack suggested in the documentation above for that method, ‘datetime(*(time.strptime(date_string, format)[0:6]))’. -- \ “Because of the impropriety of entertaining guests of the | `\opposite sex in the bedroom, it is suggested that the lobby be | _o__) used for this purpose.” —hotel, Zurich | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows, IDLE, __doc_, other
On Sun, Dec 20, 2009 at 9:16 PM, W. eWatson wrote: > When I use numpy.__doc__ in IDLE under Win XP, I get a heap of words without > reasonable line breaks. > > "\nNumPy\n=\n\nProvides\n 1. An array object of arbitrary homogeneous > items\n 2. Fast mathematical operations over arrays\n 3. Linear Algebra, > Fourier Transforms, Random Number > ... > > Is there a way to get this formated properly. > when you just do >> numpy.__doc__ you get the repr of the string, which uses the escaped characters. You'd get the same thing in the interactive interpreter. Try using print if you want to see it correctly. > If I use dir(numpy), I get yet a very long list that starts as: > ['ALLOW_THREADS', 'BUFSIZE', 'CLIP', 'DataSource', 'ERR_CALL', > 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', > 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', > 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'False_', 'Inf', 'Infinity', > 'MAXDIMS', 'MachAr', 'NAN', 'NINF', 'NZERO', 'NaN', 'PINF', 'PZERO', > 'PackageLoader', 'RAISE', 'RankWarning', 'SHIFT_DIVIDEBYZERO', > 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'ScalarType', > 'Tester', 'True_', 'UFUNC_BUFSIZE_DEFAULT' > ... > I see this might be a dictionary. What can I do to make it more readable or > useful, or is that it? Is there a more abc as in Linux? > It's a list, not a dictionary. pprint.pprint will print 1 item per line. > It the IDLE shell, it's not possible to retrieve lines entered earlier > without copying them. Is there an edit facility? > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: converting string to a date format
tekion wrote: All, I know there is a datetime module for converting and manipulate date format. I have this string date format: 24/Nov/2009:10:39:03 -0500 and would like to convert it to a date format of "2009-11-24 10:39:03". At the moment I am reading datetime module trying to find out if I could do it with datetime module. Does any one know of a way besides slashing my way through it using string split function? Use datetime.datetime.strptime() to parse the string; you'll need to remove the timezone from the string first. The format you need to provide is the same one you'd use if you were creating the string from a datetime. Then call the .strftime() method of the resulting datetime object, providing the appropriate format to create the new string. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows, IDLE, __doc_, other
On 12/21/2009 1:19 PM, W. eWatson wrote: When I use numpy.__doc__ in IDLE under Win XP, I get a heap of words without reasonable line breaks. "\nNumPy\n=\n\nProvides\n 1. An array object of arbitrary homogeneous items\n 2. Fast mathematical operations over arrays\n 3. Linear Algebra, Fourier Transforms, Random Number Is there a way to get this formated properly. help(object) If I use dir(numpy), I get yet a very long list that starts as: ['ALLOW_THREADS', 'BUFSIZE', 'CLIP', 'DataSource', 'ERR_CALL', 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'False_', 'Inf', 'Infinity', 'MAXDIMS', 'MachAr', 'NAN', 'NINF', 'NZERO', 'NaN', 'PINF', 'PZERO', 'PackageLoader', 'RAISE', 'RankWarning', 'SHIFT_DIVIDEBYZERO', 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'ScalarType', 'Tester', 'True_', 'UFUNC_BUFSIZE_DEFAULT' I see this might be a dictionary. What can I do to make it more readable or useful, or is that it? Is there a more abc as in Linux? You can use pprint module: import pprint pprint.pprint(dir(object)) though help() is usually better It the IDLE shell, it's not possible to retrieve lines entered earlier without copying them. Is there an edit facility? Press Alt+P (Previous) and Alt+N (Next). Or you can click/select on the line you want to copy and press Enter. Add to this. Isn't there a way to see the arguments and descriptions of functions? Use help(). Or if you're doing this without human intervention, use `inspect` module. -- http://mail.python.org/mailman/listinfo/python-list
converting string to a date format
All, I know there is a datetime module for converting and manipulate date format. I have this string date format: 24/Nov/2009:10:39:03 -0500 and would like to convert it to a date format of "2009-11-24 10:39:03". At the moment I am reading datetime module trying to find out if I could do it with datetime module. Does any one know of a way besides slashing my way through it using string split function? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows, IDLE, __doc_, other
Add to this. Isn't there a way to see the arguments and descriptions of functions? -- http://mail.python.org/mailman/listinfo/python-list
Windows, IDLE, __doc_, other
When I use numpy.__doc__ in IDLE under Win XP, I get a heap of words without reasonable line breaks. "\nNumPy\n=\n\nProvides\n 1. An array object of arbitrary homogeneous items\n 2. Fast mathematical operations over arrays\n 3. Linear Algebra, Fourier Transforms, Random Number ... Is there a way to get this formated properly. If I use dir(numpy), I get yet a very long list that starts as: ['ALLOW_THREADS', 'BUFSIZE', 'CLIP', 'DataSource', 'ERR_CALL', 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'False_', 'Inf', 'Infinity', 'MAXDIMS', 'MachAr', 'NAN', 'NINF', 'NZERO', 'NaN', 'PINF', 'PZERO', 'PackageLoader', 'RAISE', 'RankWarning', 'SHIFT_DIVIDEBYZERO', 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'ScalarType', 'Tester', 'True_', 'UFUNC_BUFSIZE_DEFAULT' ... I see this might be a dictionary. What can I do to make it more readable or useful, or is that it? Is there a more abc as in Linux? It the IDLE shell, it's not possible to retrieve lines entered earlier without copying them. Is there an edit facility? -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On Sun, 20 Dec 2009 07:26:03 +1100, Lie Ryan wrote: > On 12/20/2009 4:02 AM, Carl Johan Rehn wrote: > > Parallel PRNGs are an unsolved problem in computer science. >> >> Thanks again for sharing your knowledge. I had no idea. This means >> that if I want to speed up my application I have to go for the fastest >> random generator and focus on other parts of my code that can be >> vectorized. > > If you don't care about "repeatability" (which is already extremely > difficult in parallel processing even without random number generators), > you can just start two PRNG at two distinct states (and probably from > two different algorithms) and they will each spews out two independent > streams of random numbers. What was "unsolved" was the "pseudo-" part of > the random number generation, which guarantee perfect replayability in > all conditions. Why not use a good cipher, such as AES, to generate a pseudorandom bit stream by encrypting successive integers? If you use a different key for each instance, you'll have exactly the independence you want. And if you can detect any statistical anomaly in the output, you automatically have the most exciting paper to be published in the next issue of the Journal of Cryptology. Minor caveats: 1. This might be slower than another approach, but maybe not: AES is much faster than the ciphers of the old days. 2. Since AES(key,i) != AES(key,j) if i != j, there will be a dearth of duplicates, which will become statistically detectable around the time i has been incremented 2**64 times. There are many reasons why this might not bother you (one: you don't plan to use so many values; two: you might use the 128-bit AES output in pieces, rather than as a single value, in which case duplicates will appear among the pieces at the right rate), but if it *does* bother you, it can be fixed by using i^AES(key,i) instead of just AES(key,i). -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: strptime not strict enough
Chris Rebert wrote: >On Tue, Dec 15, 2009 at 9:47 PM, Tim Roberts wrote: >> Tobias Weber wrote: >>> >>>despite the directives for leading zero stime.strptime('09121', >>>'%y%m%d') returns the first of December. Shouldn't it raise ValueError? >> >> Python merely calls the strptime function in your C run-time library. If >> it sucks, so will time.strptime. > >Er, no, wrong: >http://svn.python.org/view/python/trunk/Lib/_strptime.py?view=markup Chris is right, I'm wrong. time.strptime is a C function that loads and runs the version in the _strptime.py module. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On 12/21/2009 1:13 AM, David Cournapeau wrote: But the OP case mostly like falls in your estimated 0.01% case. PRNG quality is essential for reliable Monte Carlo procedures. I don't think long period is enough to guarantee those good properties for // random generators - at least it is not obvious to me. Now it's not, long periods are not indicator of quality. I was responding to the chance of unexpected repetition of sequence because of collision of entry points. Long periods is an indicator that the chance of entry point collision should be low enough. Long periods (alone) doesn't mean anything to the quality of the randomness itself. -- http://mail.python.org/mailman/listinfo/python-list
Re: C Structure rebuild with ctypes
"Georg" wrote in message news:7p6ksnfkg...@mid.individual.net... Hi All, I need to use a library written in C. The routine "int func (int handle, int *numVars, char ***varNames, int **varTypes)" expects a complex object: " ... Variable names are structured as an array of *numVars pointers, each pointing to a char string containing a variable name, and *varNames is set to point to the first element of the array. Variable types are stored into a corresponding array of *numVars in elements, and *varTypes is set to point to the first element of the array." I tried using ctypes but nothing worked, e.g. "varNames = (c_char_p(c_char * 65) * NumberOfVariables)()" Can anyboby help? How do I have to state the structure "array of pointers to char string"? How is a pointer to the first element of such an array defined using ctypes? How do I allocate enough space for the char the array points to? Are you passing in these values, or are they being returned? To me the depth of the pointer references implies numVars, varNames, and varTypes are out parameters. I'll assume that for now. If they are in/out parameters let me know. I mocked up a DLL to test returning values of these types. I used VS2008 and compiled with "cl /LD func.c": --- func.c --- #include #define FUNCDLL #include "func.h" static char* g_data[] = {"one","two","three"}; static int g_types[] = {1,2,3}; FUNCAPI int func (int handle, int *numVars, char ***varNames, int **varTypes) { *numVars = _countof(g_data); *varNames = g_data; *varTypes = g_types; return handle + 1; } --- func.h --- #ifdef FUNCDLL #define FUNCAPI __declspec(dllexport) #else #define FUNCAPI __declspec(dllimport) #endif FUNCAPI int func (int handle, int *numVars, char ***varNames, int **varTypes); --- func.py --- import ctypes as c # shortcuts for useful types INT = c.c_int PINT = c.POINTER(INT) PPINT = c.POINTER(PINT) PCHAR = c.c_char_p PPCHAR = c.POINTER(PCHAR) PPPCHAR = c.POINTER(PPCHAR) # int func (int handle, int *numVars, char ***varNames, int **varTypes) func = c.CDLL('func').func func.restype = INT func.argtypes = [INT,PINT,PPPCHAR,PPINT] # allocate storage for the out parameters numVars = INT() varNames = PPCHAR() varTypes = PINT() print func(5,c.byref(numVars),c.byref(varNames),c.byref(varTypes)) # numVars contains size of returned arrays. Recast to access. varNamesArray = c.cast(varNames,c.POINTER(PCHAR * numVars.value)) varTypesArray = c.cast(varTypes,c.POINTER(INT * numVars.value)) for value in varNamesArray.contents: print value for value in varTypesArray.contents: print value --- output --- 6 one two three 1 2 3 Hope this helps, -Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Anybody use web2py?
People seem to think that because web2py has a default for almost everything (part of its design) than you must use the default. - There is a web based IDE but you *can* use the shell instead (like you do in Django) - There are migrations but you *can* disable then (and it works like Django that does not do migrations) - There are default views for every action but you *can* make your own - There is a default route to every action but you *can* create your own routes.py, equivalent to Django urls.py - There is a default for form layout but you *can* customize them in multiple ways - There is a default widget for every field but you *can* change it or define your own - There is a default validator for every field but you *can* change it or create your own - It comes with a default layout.html but you can user any other html/ css layout or make your own - It comes with jQuery but you *can* use any other javascript library - It default to email/password login but you *can* use other authentication methods (gmail, twitter, openid, rpx, cas, ldap). - etc. The only things that web2py does not let you customize are things that have security implications (like how sessions and uploads are handled). On Dec 20, 3:09 pm, Baron wrote: > > If all > > web2py offers is default views, then it may be good for proof of concept > > projects, however I can't see in my right mind, proofing an application, > > and then turning around to write it in django because more than the > > defaults is needed. > > You *can* customize web2py views ... > > > Why does web2py have classes that represent HTML? I can't see ever > > needing to write VIEW code in my controller, since thats what views are > > for. > > I use these in my views when a HTML tag has multiple dynamic > properties because it looks more neat. > > I came to web2py a year back after writing applications in many other > frameworks (Turbogears / Symonfy / Rails / Django) and find myself > more productive with web2py. > So as others have said - try both. Write a small application in both > to see which suits you. > > Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: When will Python 3 be fully deployed
In article , a...@pythoncraft.com (Aahz) wrote: > Looking back over the years, after I learned Python I realized that I > never really had enjoyed programming before. That's a sad commentary. Python is fun to use, but surely there are other ways you can enjoy programming? The first thing I learned how to program was an HP-9810 (http://www.hpmuseum.org/hp9810.htm). I had LOADS of fun with that. Then I learned BASIC (using my high school's ASR-33 hookup to a HP-3000 a couple of towns away). Lots of fun there too. Then came Fortran. I guess I had fun with that, at least in the beginning. I did a bunch of assembler. Some of it was fun (pdp-11, 6800), some of it was not (pdp-10, IBM-1130). Lisp was fun for a while, but I never really got into it. C was fun at the beginning, but quickly became a drag. C++ was was evil and horrible at the beginning. As opposed to now, when I'm somewhat of an expert in it, and it's still evil and horrible. Learning PostScript was blast! One of the true epiphanies of my programming career was hooking a video terminal up to the RS-232 port on an Apple LaserWriter, typing a few lines of PostScript at it, and watching a page come out with a square drawn on it. Everybody should learn PostScript. People think of it as just some document printing thing, but it's a real (Turing-complete) programming language. Not just that, but it's a fun language to learn, and lets you explore some corners of the language design space which most people never see. Go forth and learn PostScript! Learning Java was about as much fun as kissing your sister. I'm sure I've left a few out, but the point is there are plenty of ways to have fun programming besides Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt Signals and multiple sources
On Dec 21, 11:15 am, "John Posner" wrote: > On Sun, 20 Dec 2009 16:59:11 -0500, Zabin wrote: > > I am beginner in programming in pyqt. I have been trying to call the > > same function from multiple events- but each event results in a > > different instance of the function. I am just unable to figure out how > > to retrieve the source which calls the function: > > > My source signal declarations are as below: > > QtCore.QObject.connect(self.ui.Button_Process, QtCore.SIGNAL("clicked > > ()"), self.activate_tab) > > QtCore.QObject.connect(self.ui.Button_Material, QtCore.SIGNAL("clicked > > ()"), self.activate_tab) > > QtCore.QObject.connect(self.ui.Button_Geometry, QtCore.SIGNAL("clicked > > ()"), self.activate_tab) > > > for each of the above source i want to activate a different instance > > of the activate_tab function. Any help would be greatly appreciated! > > In the self.activate_tab() method, use self.sender() to determine which > object sent the signal. > > -John- Hide quoted text - > > - Show quoted text - Awesum. That works! To get the object name you just need to use self.sender().objectName() Cheers! -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt Signals and multiple sources
On Sun, 20 Dec 2009 16:59:11 -0500, Zabin wrote: I am beginner in programming in pyqt. I have been trying to call the same function from multiple events- but each event results in a different instance of the function. I am just unable to figure out how to retrieve the source which calls the function: My source signal declarations are as below: QtCore.QObject.connect(self.ui.Button_Process, QtCore.SIGNAL("clicked ()"), self.activate_tab) QtCore.QObject.connect(self.ui.Button_Material, QtCore.SIGNAL("clicked ()"), self.activate_tab) QtCore.QObject.connect(self.ui.Button_Geometry, QtCore.SIGNAL("clicked ()"), self.activate_tab) for each of the above source i want to activate a different instance of the activate_tab function. Any help would be greatly appreciated! In the self.activate_tab() method, use self.sender() to determine which object sent the signal. -John -- http://mail.python.org/mailman/listinfo/python-list
PyQt Signals and multiple sources
I am beginner in programming in pyqt. I have been trying to call the same function from multiple events- but each event results in a different instance of the function. I am just unable to figure out how to retrieve the source which calls the function: My source signal declarations are as below: QtCore.QObject.connect(self.ui.Button_Process, QtCore.SIGNAL("clicked ()"), self.activate_tab) QtCore.QObject.connect(self.ui.Button_Material, QtCore.SIGNAL("clicked ()"), self.activate_tab) QtCore.QObject.connect(self.ui.Button_Geometry, QtCore.SIGNAL("clicked ()"), self.activate_tab) for each of the above source i want to activate a different instance of the activate_tab function. Any help would be greatly appreciated! -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
Victor Subervi wrote: Inelegant. This will be elegant: ourFile = string.split(__file__, "/") p = ourFile[len(ourFile) - 1] p = p[: - 3] site = ourFile[4][:-10] if site != '': site = site[:-1] from this import that(site) Now it's automated. V Amazing. When trying to split a path string, consider using os.path.split(). When trying to get rid of the file extension, consider using os.path.splitext(). When trying to get the last item of a list, consider using subscript of -1. And when you want all but the last 10 characters of a string, use [:-11] instead of a two-step. Since you've hardcoded the directory structure (also a bad idea), this may not be quite right. But something like: site = os.path.splitext(os.path.split(__file__)[1])[0][:-8] will extract the beginning of the basename, whether it's a URL, or Linux, or Windows. But all of this has nothing to do with your original question, which said: If I have a script that is imported by another script, how can I have the script that is being imported determine which script imported it? We were all willing to overlook the misuse of the word script -- a python source file that's imported isn't a script, it's a module -- but somehow we assumed you were asking a serious question. Nothing about the code you now post has anything to do with the script that imported it. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
On Sun, Dec 20, 2009 at 3:26 PM, Stephen Hansen wrote: > On Sun, Dec 20, 2009 at 11:01 AM, Victor Subervi > wrote: > >> If you want a piece of code to have a variable number of differing >>> behaviors, that's something you can handle in many elegant ways. That's >>> something inheritance is good for, with a core default behavior represented >>> in one class and more specialized behavior represented in sub-classes. But >>> either way, you have to tell it which class to create at the moment, which >>> entails passing in a parameter explicitly activating one or the other. This >>> is a good thing. Don't try to get around it. >>> >> >> Inelegant. This will be elegant: >> >> ourFile = string.split(__file__, "/") >> p = ourFile[len(ourFile) - 1] >> p = p[: - 3] >> site = ourFile[4][:-10] >> if site != '': >> site = site[:-1] >> >> from this import that(site) >> >> Now it's automated. >> > > Since when is "automation" a synonym of "elegance"? > > Granted, elegance is something that will always be in the eye of the > beholder-- but looking at that chunk of code, I can't even figure out what > you're trying to do with it (or what that last 'from ...' line is even > supposed to mean). > It's something to plug into any page anywhere and not have to worry about tweaking it for a given page. Not reading further responses to this post. V -- http://mail.python.org/mailman/listinfo/python-list
Re: How Do I...?
Victor Subervi wrote: The aim was not arrogance, but expression of exasperation "Walk a mile in my mocassins." You can't do it. I'm an artist. I think out of my right hemisphere, not my left like you. You couldn't possibly understand. [snip] Thank you for your help anyway. Thank you for your patience. Please try to understand. It starts by understanding you can't understand. [snip] The whole universe is a program. I program to understand it in a way you couldn't even begin to grasp. I'm not sure how I become the one accused of arrogance. Or where my right-brain ceases to be as magnificent as yours and my capacity to understand you falls so short -- whether it's speaking Spanish or being conversational in ASL; authoring and illustrating a children's book; striving for beautiful code (Stephen's recent post well summarizes elegance in code); submitting my work status reports in [limerick, sonnet, rap, comic, pop-music spoof, crossword puzzle, etc]; cooking; sewing/crafting/needlework; painting; wood-working; guitar-playing; the philosophy minor; creating balloon art, etc. It would seem I use both sides of the brain, like many others on the list here. For just a single example reference, check out Adrian Holovaty (one of the Django founders) jamming some beautiful guitar-work on YouTube. The problem is that I quite literally can't think like you. I have to force myself to do it every time. To you it's as natural as breathing, which is why you can't relate. In time and with repeated exercise, it's possible to develop both sides of the brain. One side may dominate (and I'll forthrightly declare that my left brain dominates), but it doesn't excuse failure to strengthen the weaker side. You have my continued promise that I will do all I can to edit my questions as intelligently as you would before I post them. Trust me, I don't like looking foolish, and I know I do. You should recognize that that alone is chiding enough. It doesn't stop me, however, for continuing to program. I appreciate your efforts to edit -- I've provided a bit of a check-list that you can use to make sure you've googled for the obvious; taken the time understand the problem in both a local context and stepping away to see the big-picture view of the problem; taken a survey of your available tools; read the tracebacks to try and understand what they're telling you; and when you post (with replies inline), provide the code exactly as it's erroring for you (stripped down examples are nice, as long as they reproduce the problem) instead of transcribing something like your code; if you get exceptions post the full traceback not just your interpretation of them; and if you're running in a non-conventional environment such as a web-server instead of a standalone application, it's helpful to note it up front. The perennial "Smart Questions" article by ESR might also be a useful read in ingratiating yourself. By demonstrating that you've exerted the effort to help the list help you, it encourages us to provide the best answers. On the whole, the list does enjoy being helpful. And when you do get a helpful answer, saying thanks is always appreciated... I appreciate Tim's advice something I've noted you've improved on lately...thanks in return. I came across as I intended. Your intent was to come across condescendingly as a right-brained artist struggling to be understood yet obdurately plunging ahead without striving to facilitate others in helping you? -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
Victor Subervi wrote: On Sun, Dec 20, 2009 at 1:20 PM, Stephen Hansen wrote: Of course, I can pass the page name as a parameter, but that's not elegant. That is precisely what it is in fact-- elegant; it is non-elegant to have magical behavior where what 'imports' something somehow changes or determines how that something behaves. It may be possible to go into dark places to discover what code first imported a module, but its not possible to discover what code does subsequent imports-- and in either case, this is /not/ something that has any sort of elegance to it. Its deeply hackish. Inelegant. This will be elegant: [snipped atrocious malformed code that won't compile, has undocumented magic constants, and is fragilely dependent on a certain directory/naming convention] For your claims to be a right-brained artistic type, your evidenced sense of aesthetic leans towards the baroquen. Trust the list's suggestions -- your proposed code is NOT elegant. This is reinforced on multiple fronts: Stephen and MRAB have already commented this is an inelegant idea (and Chris hinted that it's undesirable) and I share their opinion; additionally, the fact that Python doesn't make this easy suggests that it's not the preferred way to do things. Yes, one can sniff stacks, check the system module cache before and after an import, or do other crazy black magic, but for your described use-case, proper architecture can be both elegant and simple as Stephen suggests. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Anybody use web2py?
> If all > web2py offers is default views, then it may be good for proof of concept > projects, however I can't see in my right mind, proofing an application, > and then turning around to write it in django because more than the > defaults is needed. You *can* customize web2py views ... > Why does web2py have classes that represent HTML? I can't see ever > needing to write VIEW code in my controller, since thats what views are > for. I use these in my views when a HTML tag has multiple dynamic properties because it looks more neat. I came to web2py a year back after writing applications in many other frameworks (Turbogears / Symonfy / Rails / Django) and find myself more productive with web2py. So as others have said - try both. Write a small application in both to see which suits you. Richard -- http://mail.python.org/mailman/listinfo/python-list
Live Video Capture using Python
Hello Guys, I am trying to capture images from a live broadcast of a "cricket match" or say any video using python. I can see the video in the browser.My aim is to capture the video at any moment and create an images.Searching on google turns up http://videocapture.sourceforge.net/ .I am not sure if this would be help here.I would appreciate if someone points me in the right direction. Thanks Aditya -- http://mail.python.org/mailman/listinfo/python-list
Re: console command to get the path of a function
On Dec 20, 12:02 pm, Terry Reedy wrote: > On 12/20/2009 7:45 AM, mattia wrote: > > > Hi all, is there a way in the python shell to list the path of a library > > function (in order to look at the source code?). > > On Windows and I believe other systems, for the stdlib, 'import x' > imports .../Pythonx.y/Lib/x Not always. For example, os.path is actually in one of ntpath.py, posixpath.py, or macpath.py. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to go back from 2.6.4 to 2.6.2 under windows ?
So I guess this is a reasonable approach, and all libraries should work well, unless one of these libraries has a work around for one of the bugs fixed between 2.6.2 and 2.6.4. Let VPython people know about this problem. People should be able to run it on the latest patched 2.6. Well this is the first line on the VPython download page ;-) "To use Visual 5.13 with Python 2.6, use Python 2.6.2, NOT later versions such as Python 2.6.3 or Python 2.6.4 or Python 3.x:" cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
On Sun, Dec 20, 2009 at 11:01 AM, Victor Subervi wrote: > If you want a piece of code to have a variable number of differing >> behaviors, that's something you can handle in many elegant ways. That's >> something inheritance is good for, with a core default behavior represented >> in one class and more specialized behavior represented in sub-classes. But >> either way, you have to tell it which class to create at the moment, which >> entails passing in a parameter explicitly activating one or the other. This >> is a good thing. Don't try to get around it. >> > > Inelegant. This will be elegant: > > ourFile = string.split(__file__, "/") > p = ourFile[len(ourFile) - 1] > p = p[: - 3] > site = ourFile[4][:-10] > if site != '': > site = site[:-1] > > from this import that(site) > > Now it's automated. > Since when is "automation" a synonym of "elegance"? Granted, elegance is something that will always be in the eye of the beholder-- but looking at that chunk of code, I can't even figure out what you're trying to do with it (or what that last 'from ...' line is even supposed to mean). To me, elegance in code is the hard-to-define and oft-saught-after unity of clarity, maintainability and functionality. For code to be elegant, you must be able to look at it in isolation and with relative ease(provided one understands the language and its idiomatic usage, of course) fully understand what it does. Its clear. You shouldn't have to look into another part of code, or worse another file, to understand it. Being clear, its purpose should be well-defined such that you can make changes to it with ease and have no worry about breaking or altering the behavior of other parts of code. Its maintainable. Being maintainable, it achieves its desired function in the best way that it can without sacrificing previous principles -- its relatively efficient without being dirtied by premature optimization, it takes advantages of the strengths of the language instead of pressing into the weaknesses. Not all code can be elegant; most can't for purely practical reasons, and that's fine. But describing spooky-action-at-a-distance behavior into modules such that which imports the code somehow changes that codes behavior as elegant? I dunno, we're operating on very different definitions at that point :) If elegance and automation are linked, then you'll find a lot of stuff in Python is inelegant, as the fundamental design of the language itself prizes explicitness as elegance, and not vice-versa. --S -- http://mail.python.org/mailman/listinfo/python-list
Re: how to go back from 2.6.4 to 2.6.2 under windows ?
On 12/20/2009 2:59 PM, Stef Mientki wrote: Benjamin Kaplan wrote: On Sun, Dec 20, 2009 at 9:26 AM, Stef Mientki wrote: hello, I've just upgraded my system from Python 2.5 to 2.6.4, and installed the latest packages of a lot of libraries. Now one essential package (VPython) only works with Python 2.6.2. I tried to install Python 2.6.2 over this 2.6.4 installation, and indeed the readme file says it's 2.6.2, but the python and pythonw are still 2.6.4. Why is that so ?? Now assume that a number of packages (because compiled with 2.6.4) will not work correctly with 2.6.2. Is that correct ? 2.6.4 is just a bugfix release- it's binary compatible with the other 2.6 releases. So any package that worked under 2.6.2 shouid also work under 2.6.4 unless a new bug was introduced or it relied on a bug that was fixed. And any package that works under 2.6.4 will also work under 2.6.2 without recompiling unless it hits one of the bugs that was fixed. thanks Benjamin, Then VPython must hit one of the bugs that were fixed. On a second machine, - I removed Python 2.6.4 (without removing all other libraries) - installed Python 2.6.2 (without reïnstalling all the libraries) and indeed the VPython library works as expected. So I guess this is a reasonable approach, and all libraries should work well, unless one of these libraries has a work around for one of the bugs fixed between 2.6.2 and 2.6.4. Let VPython people know about this problem. People should be able to run it on the latest patched 2.6. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anybody use web2py?
The concept of distributed transaction does not make sense on GAE because there is only one datastore. It supports regular transactions on GAE to the extent that GAE supports them but you have to use the GAE run_in_transaction API explictely. It does support distributed transactions with multiple database connection to postgresq, mysql and/or firebird. I think this is related to the topic because it is a distinctive feature of web2py. Massimo On Dec 20, 1:32 pm, Lacrima wrote: > On Dec 20, 1:35 am, mdipierro wrote: > > > Errata. I said "The dal supports transactions" where I meant "the dal > > supports migrations". > > Of course it also supports "transactions" as well as "distributed > > transactions". > > Sorry, if this is not related to this topic. > Does web2py support distributed transactions with Google App Engine > Datastore? -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE issue
On 12/20/2009 12:17 PM, Mohamed Musthafa Safarulla wrote: I have python 2.5 ...but when i open it, i get the below error messages Socker Error: Connection refused and IDLE's subprocess didnt make connection. Either IDLE can't start subprocess or personal firewall software is blocking the connection. Have someone encountered this issue? Please help. Yes. go to bugs.python.org and search text: 'socket error', component: IDLE for previous reports and suggestions. It is possible that upgrade will help. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: console command to get the path of a function
On 12/20/2009 7:45 AM, mattia wrote: Hi all, is there a way in the python shell to list the path of a library function (in order to look at the source code?). On Windows and I believe other systems, for the stdlib, 'import x' imports .../Pythonx.y/Lib/x -- http://mail.python.org/mailman/listinfo/python-list
Re: how to go back from 2.6.4 to 2.6.2 under windows ?
Benjamin Kaplan wrote: On Sun, Dec 20, 2009 at 9:26 AM, Stef Mientki wrote: hello, I've just upgraded my system from Python 2.5 to 2.6.4, and installed the latest packages of a lot of libraries. Now one essential package (VPython) only works with Python 2.6.2. I tried to install Python 2.6.2 over this 2.6.4 installation, and indeed the readme file says it's 2.6.2, but the python and pythonw are still 2.6.4. Why is that so ?? Now assume that a number of packages (because compiled with 2.6.4) will not work correctly with 2.6.2. Is that correct ? 2.6.4 is just a bugfix release- it's binary compatible with the other 2.6 releases. So any package that worked under 2.6.2 shouid also work under 2.6.4 unless a new bug was introduced or it relied on a bug that was fixed. And any package that works under 2.6.4 will also work under 2.6.2 without recompiling unless it hits one of the bugs that was fixed. thanks Benjamin, Then VPython must hit one of the bugs that were fixed. On a second machine, - I removed Python 2.6.4 (without removing all other libraries) - installed Python 2.6.2 (without reïnstalling all the libraries) and indeed the VPython library works as expected. So I guess this is a reasonable approach, and all libraries should work well, unless one of these libraries has a work around for one of the bugs fixed between 2.6.2 and 2.6.4. cheers, Stef So the best way would be to reinstall everything ?? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
On Sun, Dec 20, 2009 at 1:20 PM, Stephen Hansen wrote: > On Sun, Dec 20, 2009 at 3:05 AM, Victor Subervi > wrote: > >> Of course, I can pass the page name as a parameter, but that's not >> elegant. >> > > That is precisely what it is in fact-- elegant; it is non-elegant to have > magical behavior where what 'imports' something somehow changes or > determines how that something behaves. > > It may be possible to go into dark places to discover what code first > imported a module, but its not possible to discover what code does > subsequent imports-- and in either case, this is /not/ something that has > any sort of elegance to it. Its deeply hackish. > > If you want a piece of code to have a variable number of differing > behaviors, that's something you can handle in many elegant ways. That's > something inheritance is good for, with a core default behavior represented > in one class and more specialized behavior represented in sub-classes. But > either way, you have to tell it which class to create at the moment, which > entails passing in a parameter explicitly activating one or the other. This > is a good thing. Don't try to get around it. > Inelegant. This will be elegant: ourFile = string.split(__file__, "/") p = ourFile[len(ourFile) - 1] p = p[: - 3] site = ourFile[4][:-10] if site != '': site = site[:-1] from this import that(site) Now it's automated. V -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
On Sun, Dec 20, 2009 at 3:05 AM, Victor Subervi wrote: > Of course, I can pass the page name as a parameter, but that's not elegant. > That is precisely what it is in fact-- elegant; it is non-elegant to have magical behavior where what 'imports' something somehow changes or determines how that something behaves. It may be possible to go into dark places to discover what code first imported a module, but its not possible to discover what code does subsequent imports-- and in either case, this is /not/ something that has any sort of elegance to it. Its deeply hackish. If you want a piece of code to have a variable number of differing behaviors, that's something you can handle in many elegant ways. That's something inheritance is good for, with a core default behavior represented in one class and more specialized behavior represented in sub-classes. But either way, you have to tell it which class to create at the moment, which entails passing in a parameter explicitly activating one or the other. This is a good thing. Don't try to get around it. --S -- http://mail.python.org/mailman/listinfo/python-list
Re: Python3.1: gzip encoding with UTF-8 fails
"Diez B. Roggisch" wrote in message news:7p7328f3r1r2...@mid.uni-berlin.de... Johannes Bauer schrieb: > Hello group, > > with this following program: > > #!/usr/bin/python3 > import gzip > x = gzip.open("testdatei", "wb") > x.write("ä") > x.close() > > I get a broken .gzip file when decompressing: > > $ cat testdatei |gunzip > ä > gzip: stdin: invalid compressed data--length error > > As it only happens with UTF-8 characters, I suppose the gzip module UTF-8 is not unicode. Even if the source-encoding above is UTF-8, I'm not sure what is used to encode the unicode-string when it's written. > writes a length of 1 in the gzip file header (one character "ä"), but > then actually writes 2 characters (0xc3 0xa4). > > Is there a solution? What about writinga bytestring by explicitly decoding the string to utf-8 first? x.write("ä".encode("utf-8")) While that works, it still seems like a bug in gzip. If gzip.open is replaced with a simple open: # coding: utf-8 import gzip x = open("testdatei", "wb") x.write("ä") x.close() The result is: Traceback (most recent call last): File "C:\dev\python3\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 427, in ImportFile exec(codeObj, __main__.__dict__) File "", line 1, in File "y.py", line 4, in x.write("ä") TypeError: must be bytes or buffer, not str Opening a file in binary mode should require a bytes or buffer object. -Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is my namespace?
In article <00a7037c$0$15659$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: >> 2009/12/7 vsoler : >>> >>> 3. Mark says: The from statement is really an assignment to names in >>> the importer's scope--a name-copy operation, not a name aliasing. Â I >>> don't fully understand what he means. Could anybody explain? > >I'm not sure what Mark means by that either. It certainly isn't a copy >operation, it doesn't duplicate the object you imported. I don't know >what he means by aliasing, but if he means what I mean by aliasing, then >I'd say the from statement *is* an aliasing operation: it creates a new >name that refers to an existing object found by name. > >from module import name > >is roughly equivalent to: > >import module >name = module.name >del module The reason why Mark made his comment (although I think it needs some rephrasing): import module from module import name name = 'foo' print module.name is name (Of course this is all completely obvious to anyone who understands Python's name/binding semantics, but someone just learning about module imports is probably not in that category and needs some kind of warning about re-assigning names created by ``from ... import``.) -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ Looking back over the years, after I learned Python I realized that I never really had enjoyed programming before. -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
Victor Subervi wrote: Hi; I'm looking for something like os.environ['HTTP_REFERER'] but for python scripts. That is, if I have a script that is imported by another script, how can I have the script that is being imported determine which script imported it? I don't know whether that's possible (it probably is), but I do know that it's undesirable. A script shouldn't sometimes behave one way and sometimes another. Explicit is better than implicit. If you want to control its behaviour then you should do so explicitly. -- http://mail.python.org/mailman/listinfo/python-list
IDLE issue
I have python 2.5 ...but when i open it, i get the below error messages Socker Error: Connection refused and IDLE's subprocess didnt make connection. Either IDLE can't start subprocess or personal firewall software is blocking the connection. Have someone encountered this issue? Please help. -- Thanks, Musthafa -- http://mail.python.org/mailman/listinfo/python-list
Re: Invalid syntax error
On Sun, Dec 20, 2009 at 08:40:05AM -0500, Ray Holt wrote: > Why am I getting an invalid syntax error on the following: > os.chdir(c:\\Python_Modules). The error message says the colon after c You need to pass either a string literal or a variable. If you're passing a string, like you are trying to do, then you need to quote it. Also, you may want to use os.path.join() to make sure you're passing a portable pathname. -- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks" -- http://mail.python.org/mailman/listinfo/python-list
Re: os.starfile() linux
On Mon, Nov 30, 2009 at 05:35:31PM +, joao abrantes wrote: > to open a new shell and to put the output of the new python program > there.. The subprocess module is probably what you want. -- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks" -- http://mail.python.org/mailman/listinfo/python-list
Re: When will Python 3 be fully deployed
In article , Ned Deily wrote: >In article <4b20ac0a$0$1596$742ec...@news.sonic.net>, > John Nagle wrote: >> >> I'd argue against using Python 2.6 for production work. Either use >> Python 2.5, which is stable, or 3.x, which is bleeding-edge. 2.6 >> has some of the features of Python 3.x, but not all of them, and is >> neither fish nor fowl as a result. 2.6 is really more of a sideline >> that was used for trying out new features, not something suitable for >> production. > >I disagree with that advice, strongly. 2.6 not only has new features >but it has many bug fixes that have not and will not be applied to 2.5. >It is hardly a sideline. Ditto -- we had some webserver crashes that were fixed by upgrading from 2.4 to 2.6 (we were already using 2.6 in the client and decided that skipping 2.5 on the server was best). -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ Looking back over the years, after I learned Python I realized that I never really had enjoyed programming before. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with cheetah
On Dec 20, 4:54 pm, "Diez B. Roggisch" wrote: > mlowicki schrieb: > > > Hi!, i get such error when I try to install cheetah: > > > sudo easy_install cheetah > > Searching for cheetah > > Readinghttp://pypi.python.org/simple/cheetah/ > > Readinghttp://www.CheetahTemplate.org/ > > Readinghttp://sourceforge.net/project/showfiles.php?group_id=28961 > > Readinghttp://www.cheetahtemplate.org/ > > Best match: Cheetah 2.4.1.linux-x86-64 > > Downloadinghttp://pypi.python.org/packages/2.6/C/Cheetah/Cheetah-2.4.1.linux-x86... > > Processing Cheetah-2.4.1.linux-x86_64.tar.gz > > error: Couldn't find a setup script in /tmp/easy_install-uv6Ms_/ > > Cheetah-2.4.1.linux-x86_64.tar.gz > > I don't know who created that package, but after downloading and listing > it's contents it seems it is not a proper python egg or source distribution. > > Try to download cheetah yourself from here: > > http://pypi.python.org/packages/source/C/Cheetah/Cheetah-2.4.0.tar.gz... > > Extract & build it your own, with > > source-package $ sudo easy_install . > > Diez Thanks Diez! when I run: sudo easy_install http://pypi.python.org/packages/source/C/Cheetah/Cheetah-2.4.0.tar.gz#md5=873f5440676355512f176fc4ac01011e it works. By I need also put Cheetah to install_requires in setup.py like this: setup( name="django-yuidoc", version="0.1", zip_safe=False, packages=find_packages(), install_requires=["setuptools", "Pygments", "SimpleJSON", "Cheetah", ], ) and install this package with buildout but I get "error: Couldn't find a setup script [...]" and workaround with pass the url doesn't work with here (An internal error occured due to a bug in either zc.buildout or in a recipe being used) -- http://mail.python.org/mailman/listinfo/python-list
Re: opening a connection to quickbooks
In article , wrote: > >Has anyone ever attempted to work with quickbooks in a real time fashion? I >need some advise. I'm trying to work out a way to have real time >updates/inserts/and queries. I'd also like not to use all the user >licenses. But... > >I have discovered that opening a connection to quickbooks takes a long >time (as much as 11 seconds). Is there a way I can open/create the >connection in a thread (so the rest of the prog can continue) and then >use the connection in the rest of the program to make queries? Or does >someone have a suggestion as how to get around this problem. Are you trying to use the XML interface or the COM interface? Either way, probably using a thread would work. (Note that I actually know very little about QB -- I just had a research project a couple of months ago about trying to integrate with it.) -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ Looking back over the years, after I learned Python I realized that I never really had enjoyed programming before. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python3.1: gzip encoding with UTF-8 fails
Johannes Bauer schrieb: Hello group, with this following program: #!/usr/bin/python3 import gzip x = gzip.open("testdatei", "wb") x.write("ä") x.close() I get a broken .gzip file when decompressing: $ cat testdatei |gunzip ä gzip: stdin: invalid compressed data--length error As it only happens with UTF-8 characters, I suppose the gzip module UTF-8 is not unicode. Even if the source-encoding above is UTF-8, I'm not sure what is used to encode the unicode-string when it's written. writes a length of 1 in the gzip file header (one character "ä"), but then actually writes 2 characters (0xc3 0xa4). Is there a solution? What about writinga bytestring by explicitly decoding the string to utf-8 first? x.write("ä".encode("utf-8")) Diez -- http://mail.python.org/mailman/listinfo/python-list
Multithreaded python program freezes
Hello, I have some problems with a http proxy which is implemented in Python 2.6. A few times a day, the proxy begins using 100% CPU and doesn't work any more. I have created a thread dump when the problem occurs here: http://www.pvv.ntnu.no/~andrearo/thread-dump.html This is a thread dump during normal operation: http://www.pvv.ntnu.no/~andrearo/thread-dump-normal.html The source code can be found here: http://code.google.com/p/freeciv-forever/source/browse/trunk/freeciv-proxy/ The application is heavily multi-threaded, since its main function is being a proxy converting packets containing C struct data to JSON over HTTP. Any advice on why this Python program appears to freeze? Is there anything more I can do to find out why this problem occurs? Andreas R -- http://mail.python.org/mailman/listinfo/python-list
Re: how to go back from 2.6.4 to 2.6.2 under windows ?
On Sun, Dec 20, 2009 at 9:26 AM, Stef Mientki wrote: > hello, > > I've just upgraded my system from Python 2.5 to 2.6.4, > and installed the latest packages of a lot of libraries. > > Now one essential package (VPython) only works with Python 2.6.2. > I tried to install Python 2.6.2 over this 2.6.4 installation, > and indeed the readme file says it's 2.6.2, > but the python and pythonw are still 2.6.4. > Why is that so ?? > > Now assume that a number of packages (because compiled with 2.6.4) will not > work correctly with 2.6.2. > Is that correct ? > 2.6.4 is just a bugfix release- it's binary compatible with the other 2.6 releases. So any package that worked under 2.6.2 shouid also work under 2.6.4 unless a new bug was introduced or it relied on a bug that was fixed. And any package that works under 2.6.4 will also work under 2.6.2 without recompiling unless it hits one of the bugs that was fixed. > So the best way would be to reinstall everything ?? > > thanks, > Stef Mientki > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Classes
Dave Angel wrote: [...] > We were talking about 2.x And I explicitly mentioned 3.x because if > one develops code that depends on old-style classes, they'll be in > trouble with 3.x, which has no way to specify old-style classes. In > 3.x, all classes are new-style. And although it'll no longer matter > whether you specify (object), it doesn't do any harm. As I said, it's a > good habit for a beginner to get into when defining classes. > I maintain that this almost-cargo-cult belief over-complicates things for language beginners. How long do you have to be using Python before you make your first super() call? How many programs behave differently with old-style vs. new-style classes? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Python3.1: gzip encoding with UTF-8 fails
Hello group, with this following program: #!/usr/bin/python3 import gzip x = gzip.open("testdatei", "wb") x.write("ä") x.close() I get a broken .gzip file when decompressing: $ cat testdatei |gunzip ä gzip: stdin: invalid compressed data--length error As it only happens with UTF-8 characters, I suppose the gzip module writes a length of 1 in the gzip file header (one character "ä"), but then actually writes 2 characters (0xc3 0xa4). Is there a solution? Regards, Johannes -- "Aus starken Potentialen können starke Erdbeben resultieren; es können aber auch kleine entstehen - und "du" wirst es nicht für möglich halten (!), doch sieh': Es können dabei auch gar keine Erdbeben resultieren." -- "Rüdiger Thomas" alias Thomas Schulz in dsa über seine "Vorhersagen" <1a30da36-68a2-4977-9eed-154265b17...@q14g2000vbi.googlegroups.com> -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with cheetah
mlowicki schrieb: Hi!, i get such error when I try to install cheetah: sudo easy_install cheetah Searching for cheetah Reading http://pypi.python.org/simple/cheetah/ Reading http://www.CheetahTemplate.org/ Reading http://sourceforge.net/project/showfiles.php?group_id=28961 Reading http://www.cheetahtemplate.org/ Best match: Cheetah 2.4.1.linux-x86-64 Downloading http://pypi.python.org/packages/2.6/C/Cheetah/Cheetah-2.4.1.linux-x86_64.tar.gz#md5=98cda0e846db7988f43a6b2acf00a527 Processing Cheetah-2.4.1.linux-x86_64.tar.gz error: Couldn't find a setup script in /tmp/easy_install-uv6Ms_/ Cheetah-2.4.1.linux-x86_64.tar.gz I don't know who created that package, but after downloading and listing it's contents it seems it is not a proper python egg or source distribution. Try to download cheetah yourself from here: http://pypi.python.org/packages/source/C/Cheetah/Cheetah-2.4.0.tar.gz#md5=873f5440676355512f176fc4ac01011e Extract & build it your own, with source-package $ sudo easy_install . Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Invalid syntax error
On Sun, 20 Dec 2009 08:40:05 -0500 "Ray Holt" wrote: > Why am I getting an invalid syntax error on the following: > os.chdir(c:\\Python_Modules). The error message says the colon after c is You forgot the quotes around the string. I am not on Windows but I think the following will all work. os.chdir("c:\\Python_Modules") os.chdir(r"c:\Python_Modules") os.chdir("c:/Python_Modules") I won't swear to that last one but other languages handle it. Try them. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: console command to get the path of a function
mattia wrote: Hi all, is there a way in the python shell to list the path of a library function (in order to look at the source code?). Thanks, Mattia If you know what module it's in, you can use themodule.__file__ But realize that this will only work if the module has been imported, and might not if the module is implemented in C. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: comparing dialects of csv-module
quote: d = csv.Sniffer().sniff("1,2,3") def eq(a, b, attributes=[name for name in dir(d) if not > name.startswith("_")]): > ... return all(getattr(a, n, None) == getattr(b, n, None) for n in > attributes) Only change I made is substituting "dir(csv.excel)" or "dir(csv.Dialect)" for "dir(d)", because I can't be always sure, that there'd be a nicely defined "d". Salute, Malte -- http://mail.python.org/mailman/listinfo/python-list
problem with cheetah
Hi!, i get such error when I try to install cheetah: sudo easy_install cheetah Searching for cheetah Reading http://pypi.python.org/simple/cheetah/ Reading http://www.CheetahTemplate.org/ Reading http://sourceforge.net/project/showfiles.php?group_id=28961 Reading http://www.cheetahtemplate.org/ Best match: Cheetah 2.4.1.linux-x86-64 Downloading http://pypi.python.org/packages/2.6/C/Cheetah/Cheetah-2.4.1.linux-x86_64.tar.gz#md5=98cda0e846db7988f43a6b2acf00a527 Processing Cheetah-2.4.1.linux-x86_64.tar.gz error: Couldn't find a setup script in /tmp/easy_install-uv6Ms_/ Cheetah-2.4.1.linux-x86_64.tar.gz -- http://mail.python.org/mailman/listinfo/python-list
how to go back from 2.6.4 to 2.6.2 under windows ?
hello, I've just upgraded my system from Python 2.5 to 2.6.4, and installed the latest packages of a lot of libraries. Now one essential package (VPython) only works with Python 2.6.2. I tried to install Python 2.6.2 over this 2.6.4 installation, and indeed the readme file says it's 2.6.2, but the python and pythonw are still 2.6.4. Why is that so ?? Now assume that a number of packages (because compiled with 2.6.4) will not work correctly with 2.6.2. Is that correct ? So the best way would be to reinstall everything ?? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On Sun, Dec 20, 2009 at 6:47 PM, Lie Ryan wrote: > On 12/20/2009 2:53 PM, sturlamolden wrote: >> >> On 20 Des, 01:46, Lie Ryan wrote: >> >>> Not necessarily, you only need to be certain that the two streams don't >>> overlap in any reasonable amount of time. For that purpose, you can use >>> a PRNG that have extremely high period like Mersenne Twister and puts >>> the generators to very distant states. >> >> Except there is no way to find two very distant states and prove they >> are distant enough. >> > Except only theoretical scientist feel the need to prove it and perhaps > perhaps for cryptographic-level security. Random number for games, random > number for tmp files, and 99.99% random number users doesn't really need > such proves. But the OP case mostly like falls in your estimated 0.01% case. PRNG quality is essential for reliable Monte Carlo procedures. I don't think long period is enough to guarantee those good properties for // random generators - at least it is not obvious to me. David -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments
Hi, 10 details I forgot in my first response... * John Posner: [...] Chapter 2, which current runs 98 pages! The chapter 2 PDF I posted on http://tinyurl.com/programmingbookP3> was and is (it's not been updated) 101 pages, with an "-EOT-" at page 102. I suspect you may have read the previous version. However, I believe the only difference from the previous version is the added text, the last three pages, about dictionaries (associative arrays). Did your PDF have Lewis Carrol's Jabberwocky nonsense poem somewhere in the last three pages? I used that poem as an example text for word counting? [snip] As I've said in this forum (and the edu-sig forum) before, I think the best metaphor for understanding Python variable assignment is John Zelle's yellow-sticky-note metaphor. [2] [snip] [2] "Python Programming: An Introduction to Computer Science" by John Zelle (Franklin, Biddle & Associates, 2004) See Section 2.5.1, "Simple Assignment" I'm unable to find anything about yellow sticky-notes there! However, I can guess what it was about :-), and I only looked in a PDF I downloaded, which probably was illegal and manually typed in by some kid. He he, they do a great service for us who don't have ready continuous access to a university library! Cheers, - Alf PS: Argh! Someone did it -- serious programming intro based on Python -- already! However, there's a difference between computer science and programming, as very clearly explained by Bjarne Stroustrup in his latest book; Zelle uses Python 2.x in Linux, while I use 3.x in Windows, more accessible to the average reader; Zelle's book seems to be at least partially assuming a school environment while what I'm writing is /meant/ to be sufficient for unassisted self study; and of course I think my progression is better, e.g. introducing loops and decisions very early. However, all those exercises... I wish Someone(TM) could cook up Really Interesting exercises for my manuscript! :-P -- http://mail.python.org/mailman/listinfo/python-list
Re: Invalid syntax error
Putting quotemarks "" around the path would be a good start, I think. Cheers, Xav On Sun, Dec 20, 2009 at 11:40 PM, Ray Holt wrote: > Why am I getting an invalid syntax error on the following: > os.chdir(c:\\Python_Modules). The error message says the colon after c is > invalid syntax. Why is it saying this when I am trying to change directory > to c:\Python_Modules. Thanks, Ray > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Invalid syntax error
Why am I getting an invalid syntax error on the following: os.chdir(c:\\Python_Modules). The error message says the colon after c is invalid syntax. Why is it saying this when I am trying to change directory to c:\Python_Modules. Thanks, Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: console command to get the path of a function
mattia wrote: > Il Sun, 20 Dec 2009 13:53:18 +0100, Irmen de Jong ha scritto: > >> On 12/20/2009 1:45 PM, mattia wrote: >>> Hi all, is there a way in the python shell to list the path of a >>> library function (in order to look at the source code?). >>> >>> Thanks, Mattia >> >> something like this? >> >> >>> import inspect >> >>> import os >> >>> inspect.getsourcefile(os.path.split) >> 'C:\\Python26\\lib\\ntpath.py' >> >>> print inspect.getsource(os.path.split) >> def split(p): >> """Split a pathname. >> ... >> ... >> >> >> --irmen > > Ok, but how can I retrieve information about built-in functions (if any)? > inspect.getsourcefile(itertools.product) > Traceback (most recent call last): > File "", line 1, in > File "C:\Python31\lib\inspect.py", line 439, in getsourcefile > filename = getfile(object) > File "C:\Python31\lib\inspect.py", line 406, in getfile > raise TypeError('arg is a built-in class') > TypeError: arg is a built-in class To get to the source of functions written in C you have to download the source distribution, or you can browse the subversion tree: http://svn.python.org/view/python/trunk/Modules/itertoolsmodule.c?view=markup Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: console command to get the path of a function
Il Sun, 20 Dec 2009 13:53:18 +0100, Irmen de Jong ha scritto: > On 12/20/2009 1:45 PM, mattia wrote: >> Hi all, is there a way in the python shell to list the path of a >> library function (in order to look at the source code?). >> >> Thanks, Mattia > > something like this? > > >>> import inspect > >>> import os > >>> inspect.getsourcefile(os.path.split) > 'C:\\Python26\\lib\\ntpath.py' > >>> print inspect.getsource(os.path.split) > def split(p): > """Split a pathname. > ... > ... > > > --irmen Ok, but how can I retrieve information about built-in functions (if any)? >>> inspect.getsourcefile(itertools.product) Traceback (most recent call last): File "", line 1, in File "C:\Python31\lib\inspect.py", line 439, in getsourcefile filename = getfile(object) File "C:\Python31\lib\inspect.py", line 406, in getfile raise TypeError('arg is a built-in class') TypeError: arg is a built-in class -- http://mail.python.org/mailman/listinfo/python-list
Re: console command to get the path of a function
Il Sun, 20 Dec 2009 13:53:18 +0100, Irmen de Jong ha scritto: > On 12/20/2009 1:45 PM, mattia wrote: >> Hi all, is there a way in the python shell to list the path of a >> library function (in order to look at the source code?). >> >> Thanks, Mattia > > something like this? > > >>> import inspect > >>> import os > >>> inspect.getsourcefile(os.path.split) > 'C:\\Python26\\lib\\ntpath.py' > >>> print inspect.getsource(os.path.split) > def split(p): > """Split a pathname. > ... > ... > > > --irmen Perfect, thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: py itertools?
Il Sun, 20 Dec 2009 03:49:35 -0800, Chris Rebert ha scritto: >> On Dec 19, 12:48 pm, Chris Rebert wrote: >>> On Sat, Dec 19, 2009 at 2:54 AM, mattia wrote: >>> > Hi all, I need to create the permutation of two strings but without >>> > repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my >>> > solution, but maybe the python library provides something better: >>> >>> def mcd(a, b): >>> > ... if b == 0: >>> > ... return a >>> > ... else: >>> > ... return mcd(b, a % b) >>> > ... >>> def mcm(a, b): >>> > ... return int((a * b) / mcd(a, b)) ... >>> s1 = 'abc' >>> s2 = 'wt' >>> m = mcm(len(s1), len(s2)) >>> set(zip(s1*m, s2*m)) >>> > {('a', 'w'), ('a', 't'), ('b', 'w'), ('c', 't'), ('b', 't'), ('c', >>> > 'w')} >>> >>> > Any help? >>> >>> Surprised you didn't think of the seemingly obvious approach: >>> >>> def permute_chars(one, two): >>> for left in set(one): >>> for right in set(two): >>> yield (left, right) >>> >>> >>> list(permute_chars('abc', 'wt')) >>> >>> [('a', 'w'), ('a', 't'), ('b', 'w'), ('b', 't'), ('c', 'w'), ('c', >>> 't')] > > On Sun, Dec 20, 2009 at 3:21 AM, Parker wrote: > a = 'qwerty' > b = '^%&$#' > c = [(x,y) for x in a for y in b] > c >> [('q', '^'), ('q', '%'), ('q', '&'), ('q', '$'), ('q', '#'), ('w', >> '^'), ('w', '%'), ('w', '&'), ('w', '$'), ('w', '#'), ('e', '^'), ('e', >> '%'), ('e', '&'), ('e', '$'), ('e', '#'), ('r', '^'), ('r', '%'), ('r', >> '&'), ('r', '$'), ('r', '#'), ('t', '^'), ('t', '%'), ('t', '&'), ('t', >> '$'), ('t', '#'), ('y', '^'), ('y', '%'), ('y', '&'), ('y', '$'), ('y', >> '#')] >> >> >> This one is better and simple. > > But fails if either of the input strings has repeated characters. > (Although writing it as a comprehension is indeed much briefer.) > > Whether this matters, who knows, since the OP's spec for the function > was rather vague... > > Cheers, > Chris Having non-repeating values metter. -- http://mail.python.org/mailman/listinfo/python-list
Re: console command to get the path of a function
On 12/20/2009 1:45 PM, mattia wrote: Hi all, is there a way in the python shell to list the path of a library function (in order to look at the source code?). Thanks, Mattia something like this? >>> import inspect >>> import os >>> inspect.getsourcefile(os.path.split) 'C:\\Python26\\lib\\ntpath.py' >>> print inspect.getsource(os.path.split) def split(p): """Split a pathname. ... ... --irmen -- http://mail.python.org/mailman/listinfo/python-list
C Structure rebuild with ctypes
Hi All, I need to use a library written in C. The routine "int func (int handle, int *numVars, char ***varNames, int **varTypes)" expects a complex object: " ... Variable names are structured as an array of *numVars pointers, each pointing to a char string containing a variable name, and *varNames is set to point to the first element of the array. Variable types are stored into a corresponding array of *numVars in elements, and *varTypes is set to point to the first element of the array." I tried using ctypes but nothing worked, e.g. "varNames = (c_char_p(c_char * 65) * NumberOfVariables)()" Can anyboby help? How do I have to state the structure "array of pointers to char string"? How is a pointer to the first element of such an array defined using ctypes? How do I allocate enough space for the char the array points to? Best regards Georg -- http://mail.python.org/mailman/listinfo/python-list
console command to get the path of a function
Hi all, is there a way in the python shell to list the path of a library function (in order to look at the source code?). Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list
Re: How Do I...?
Victor Subervi wrote: > On Sat, Dec 19, 2009 at 8:04 PM, Steve Holden, Chairman, PSF > mailto:chair...@python.org>> wrote: > > Well, if we were looking for arrogance we could easily interpret that > last statement as such. Please remember that although we are mainly > left-brain types on this list some of us do have artistic and musical > skills. Some people will therefore probably be closer to your conception > than you anticipate (though I confess I am unlikely to be one of them). > > > Go here: > http://logos.13gems.com/ > if you really want to understand what I mean. It's not arrogance. It's > the recognition that I simply haven't met anyone who can penetrate what > I've discovered, even though I prove it factually, and it requires heavy > right-brain functionality. Even that book is but a glimpse into what > I've seen. > > Tim is correct, the Python list is a pretty friendly place as far as > netiquette standards go, and I am happy this thread didn't just turn > into ugly name calling (which it could have with a less adult approach > by the participants). > > > Good work, Steve! Two cheers! BTW, since I see I'm dealing with the > chairman of this organization, many years ago I got booted off this list > because (apparently) whoever was in charge of the list at that time > decided to boot me off when the people running the Zope list booted me > off, apparently because of my difficulties with programming. I didn't > deserve to be booted off the Zope list, much less this one! Ever since > then, I've been signing up under different pseudonames, the latest of > which is "Victor Subervi". My legal name (changed to) is actually > "beno". I would prefer to re-sign up under that. May I? If not, I'll put > Victor out of his misery and create another fictitious character. Silly > game I've had to play. Indeed, the whole concept of booting people off > lists is absurd on its face. The approach I see in your post indicates a > much more practical approach based in a profound level of maturity. Let > me know. > beno I'm not aware that the python-list is subject to that kind of censorship. I don't see why you can't subscribe under any name you want, and I'm certainly not aware of any banning mechanism. However, you over-estimate the powers of the PSF chairman if you think I have anything to do with who gets to use the mailing list and who doesn't ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: tarfiles usage on python 2.4.4
On Dec 19, 9:27 am, tekion wrote: > All, > I am using tarfile module and my python is version 2.4.4. When I call > method extractall, I am getting error method does not exist. Could > someone confirm if the method exist on python 2.4.4? Thanks dir(tarfile) check if is exist -- http://mail.python.org/mailman/listinfo/python-list
Re: py itertools?
> On Dec 19, 12:48 pm, Chris Rebert wrote: >> On Sat, Dec 19, 2009 at 2:54 AM, mattia wrote: >> > Hi all, I need to create the permutation of two strings but without >> > repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my >> > solution, but maybe the python library provides something better: >> >> def mcd(a, b): >> > ... if b == 0: >> > ... return a >> > ... else: >> > ... return mcd(b, a % b) >> > ... >> def mcm(a, b): >> > ... return int((a * b) / mcd(a, b)) >> > ... >> s1 = 'abc' >> s2 = 'wt' >> m = mcm(len(s1), len(s2)) >> set(zip(s1*m, s2*m)) >> > {('a', 'w'), ('a', 't'), ('b', 'w'), ('c', 't'), ('b', 't'), ('c', 'w')} >> >> > Any help? >> >> Surprised you didn't think of the seemingly obvious approach: >> >> def permute_chars(one, two): >> for left in set(one): >> for right in set(two): >> yield (left, right) >> >> >>> list(permute_chars('abc', 'wt')) >> >> [('a', 'w'), ('a', 't'), ('b', 'w'), ('b', 't'), ('c', 'w'), ('c', 't')] On Sun, Dec 20, 2009 at 3:21 AM, Parker wrote: a = 'qwerty' b = '^%&$#' c = [(x,y) for x in a for y in b] c > [('q', '^'), ('q', '%'), ('q', '&'), ('q', '$'), ('q', '#'), ('w', > '^'), ('w', '%'), ('w', '&'), ('w', '$'), ('w', '#'), ('e', '^'), > ('e', '%'), ('e', '&'), ('e', '$'), ('e', '#'), ('r', '^'), ('r', > '%'), ('r', '&'), ('r', '$'), ('r', '#'), ('t', '^'), ('t', '%'), > ('t', '&'), ('t', '$'), ('t', '#'), ('y', '^'), ('y', '%'), ('y', > '&'), ('y', '$'), ('y', '#')] > > > This one is better and simple. But fails if either of the input strings has repeated characters. (Although writing it as a comprehension is indeed much briefer.) Whether this matters, who knows, since the OP's spec for the function was rather vague... Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Problem
On Sun, Dec 20, 2009 at 3:34 AM, Victor Subervi wrote: > But I get this error: > > /var/www/html/angrynates.com/cart/createTables2.py > 263 > 264 ''' > 265 > 266 createTables2() > 267 > createTables2 = > /var/www/html/angrynates.com/cart/createTables2.py in createTables2() > 105 these.append(basic) > 106 i = 0 > 107 specialtyStore = addStore() > 108 addStore = [] Rename this list so its name isn't the same as the addStore() function which you call. For more info, see: http://groups.google.com/group/comp.lang.python/browse_thread/thread/46b4c8af3196caaa?pli=1 > 109 addStore.append(specialtyStore) > specialtyStore undefined, global addStore = > > UnboundLocalError: local variable 'addStore' referenced before assignment > args = ("local variable 'addStore' referenced before assignment",) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Import Problem
Hi; I have this import statement: from particulars import storePrimaryStandAlone, addStore, ourStores particulars.py has this code: def addStore(): return 'jewelry' def ourStores(): return ['products', 'prescriptions'] def storePrimaryStandAlone(): return 'prescriptions' But I get this error: /var/www/html/angrynates.com/cart/createTables2.py 263 264 ''' 265 266 createTables2() 267 createTables2 = /var/www/html/angrynates.com/cart/createTables2.py in createTables2() 105 these.append(basic) 106 i = 0 107 specialtyStore = addStore() 108 addStore = [] 109 addStore.append(specialtyStore) specialtyStore undefined, global addStore = UnboundLocalError: local variable 'addStore' referenced before assignment args = ("local variable 'addStore' referenced before assignment",) What's strange is that it imports ourStores just fine. but even if I copy ourStores to addStore the latter doesn't get imported! Why? Now, I've worked around this problem by just importing all of particulars, but why did my import fail? TIA, Victor -- http://mail.python.org/mailman/listinfo/python-list
Re: py itertools?
>>> a = 'qwerty' >>> b = '^%&$#' >>> c = [(x,y) for x in a for y in b] >>> c [('q', '^'), ('q', '%'), ('q', '&'), ('q', '$'), ('q', '#'), ('w', '^'), ('w', '%'), ('w', '&'), ('w', '$'), ('w', '#'), ('e', '^'), ('e', '%'), ('e', '&'), ('e', '$'), ('e', '#'), ('r', '^'), ('r', '%'), ('r', '&'), ('r', '$'), ('r', '#'), ('t', '^'), ('t', '%'), ('t', '&'), ('t', '$'), ('t', '#'), ('y', '^'), ('y', '%'), ('y', '&'), ('y', '$'), ('y', '#')] This one is better and simple. On Dec 19, 12:48 pm, Chris Rebert wrote: > On Sat, Dec 19, 2009 at 2:54 AM, mattia wrote: > > Hi all, I need to create the permutation of two strings but without > > repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my > > solution, but maybe the python library provides something better: > > def mcd(a, b): > > ... if b == 0: > > ... return a > > ... else: > > ... return mcd(b, a % b) > > ... > def mcm(a, b): > > ... return int((a * b) / mcd(a, b)) > > ... > s1 = 'abc' > s2 = 'wt' > m = mcm(len(s1), len(s2)) > set(zip(s1*m, s2*m)) > > {('a', 'w'), ('a', 't'), ('b', 'w'), ('c', 't'), ('b', 't'), ('c', 'w')} > > > Any help? > > Surprised you didn't think of the seemingly obvious approach: > > def permute_chars(one, two): > for left in set(one): > for right in set(two): > yield (left, right) > > >>> list(permute_chars('abc', 'wt')) > > [('a', 'w'), ('a', 't'), ('b', 'w'), ('b', 't'), ('c', 'w'), ('c', 't')] > > Cheers, > Chris > --http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
On Sun, Dec 20, 2009 at 5:18 AM, Chris Rebert wrote: > On Sun, Dec 20, 2009 at 2:06 AM, Victor Subervi > wrote: > > Hi; > > I'm looking for something like os.environ['HTTP_REFERER'] but for python > > scripts. That is, if I have a script that is imported by another script, > how > > can I have the script that is being imported determine which script > imported > > it? > > Allow me to ask the meta-question of: Why do you want to do that? > There is quite possibly a better means to accomplish whatever end you have. > I'm writing a shopping cart in which I'm automating as much as is possible. The problem is that certain kinds of shopping carts have certain peculiar needs that must be accommodated. For example, a shopping cart for pharmaceuticals requires authentication and identification of the visitor before serving the "products" available to the visitor and specific to the visitor (their prescriptions); the jewelry shopping cart I'm building will enable automatic pricing updates based on the spot prices of the various metals. I've realized that I can call specific programs from the pages where these special functionalities will need to be incorporated and then programmatically do the necessary. Of course, I can pass the page name as a parameter, but that's not elegant. TIA, V -- http://mail.python.org/mailman/listinfo/python-list
Re: Mails & encoding
On Sun, Dec 20, 2009 at 2:46 AM, Lord Eldritch wrote: > - When I have: > > ttext='áá' > > I get a warning sendinme to this page > > http://www.python.org/peps/pep-0263.html > > Should I understand that PEP has been already implemented and follow it? Yes. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Mails & encoding
I have a CGI written in Python to process a form a read/write a text file (a minimal database). It runs in a Linux box with and it looks all the encoding is UTF8. Now I have two questions: - When I have: ttext='áá' I get a warning sendinme to this page http://www.python.org/peps/pep-0263.html Should I understand that PEP has been already implemented and follow it? - Related to the former one: the CGI sends an email with stress marks and other characters. I can read it with out any problem in my Kmail client because it detects the encoding. But I saw that most of the users are gonna read it in a webmail service where the characters (UTF8) are not recognized. Can I force a encoding when I send an email? kind of: mail(adress,'My title', mytext.encode'iso9865') Thanks in advance. -- Lord Eldritch -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variables static by default?
On Sat, 19 Dec 2009 20:28:07 -0800, Chris Rebert wrote: >> Surely, since string variables are strings, and float variables are >> floats, and bool variables are bools, and module variables are modules, >> a class variable will be a class and an instance variable will be an >> instance? > > As they say, the exception proves the rule. :) http://www.worldwidewords.org/qa/qa-exc1.htm -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Something Like os.environ['HTTP_REFERER']
On Sun, Dec 20, 2009 at 2:06 AM, Victor Subervi wrote: > Hi; > I'm looking for something like os.environ['HTTP_REFERER'] but for python > scripts. That is, if I have a script that is imported by another script, how > can I have the script that is being imported determine which script imported > it? Allow me to ask the meta-question of: Why do you want to do that? There is quite possibly a better means to accomplish whatever end you have. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Something Like os.environ['HTTP_REFERER']
Hi; I'm looking for something like os.environ['HTTP_REFERER'] but for python scripts. That is, if I have a script that is imported by another script, how can I have the script that is being imported determine which script imported it? TIA, Victor -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments
On Sun, 20 Dec 2009 08:29:43 +0100, Alf P. Steinbach wrote: > I recently (just weeks > ago) was astounded to see that a C++ "expert" thought that Java had pass > by reference, apparently because in Java only references are passed > around. The Java community, for some bizarre reason, has a tendency to describe Java's argument passing model (which is identical to Python's) as "pass by reference" even though it is nothing like pass by reference in languages that actually have it (such as Pascal). There is nothing so simple that it can't be totally confused by sufficiently stupid terminology. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy performance and random numbers
On 12/20/2009 2:53 PM, sturlamolden wrote: On 20 Des, 01:46, Lie Ryan wrote: Not necessarily, you only need to be certain that the two streams don't overlap in any reasonable amount of time. For that purpose, you can use a PRNG that have extremely high period like Mersenne Twister and puts the generators to very distant states. Except there is no way to find two very distant states and prove they are distant enough. Except only theoretical scientist feel the need to prove it and perhaps perhaps for cryptographic-level security. Random number for games, random number for tmp files, and 99.99% random number users doesn't really need such proves. And don't forget the effect of the very long period of PRNG like Mersenne Twister (2**19937 − 1, according to Wikipedia) makes it very unlikely to choose two different seeds and ended up in nearby entry point. Let's just assume we're using a 2**64-bit integer as the seeds and let's assume the entry point defined by these seeds are uniformly distributed you would to generate (on average) 2.34E+5982 numbers before you clashes with the nearest entry point. Such amount of numbers would require decades to generate. Your seed generator guard would only need to prevent seeding parallel generators with the same seed (which is disastrous), and that's it, the big period covers everything else. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do I set a Python installation as the default under windows ?
Steve Holden wrote: Stef Mientki wrote: hello, I just upgraded from Python 2.5 to 2.6. Most of the things work, but I'm struggling with one issue, when I start Python in a command window, it still uses Python 2.5. Is there a way to get Python 2.6 as my default Python environment ? thanks, Stef Mientki It's a matter of replacing C:\Python25 with C:\Python26 in your PATH environment variable, which is what the Windows command processor uses to fined executable programs. Thanks Steve, that works exactly as you say. cheers, Stef It's normal to add both the directory the interpreter lives in /and/ its Scripts subdirectory, so you may have two replacements to make. See http://www.python.org/doc/faq/windows/ for more. If anyone has any good updates to that document I'll be happy to make them (or give you permission to make them ...). It was written a long time ago, and I'm not sure it's had much love. In particular there'll not be anything relating to Windows 7. regards Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: How Do I...?
On Sat, Dec 19, 2009 at 8:04 PM, Steve Holden, Chairman, PSF < chair...@python.org> wrote: > Well, if we were looking for arrogance we could easily interpret that > last statement as such. Please remember that although we are mainly > left-brain types on this list some of us do have artistic and musical > skills. Some people will therefore probably be closer to your conception > than you anticipate (though I confess I am unlikely to be one of them). > Go here: http://logos.13gems.com/ if you really want to understand what I mean. It's not arrogance. It's the recognition that I simply haven't met anyone who can penetrate what I've discovered, even though I prove it factually, and it requires heavy right-brain functionality. Even that book is but a glimpse into what I've seen. Tim is correct, the Python list is a pretty friendly place as far as > netiquette standards go, and I am happy this thread didn't just turn > into ugly name calling (which it could have with a less adult approach > by the participants). > Good work, Steve! Two cheers! BTW, since I see I'm dealing with the chairman of this organization, many years ago I got booted off this list because (apparently) whoever was in charge of the list at that time decided to boot me off when the people running the Zope list booted me off, apparently because of my difficulties with programming. I didn't deserve to be booted off the Zope list, much less this one! Ever since then, I've been signing up under different pseudonames, the latest of which is "Victor Subervi". My legal name (changed to) is actually "beno". I would prefer to re-sign up under that. May I? If not, I'll put Victor out of his misery and create another fictitious character. Silly game I've had to play. Indeed, the whole concept of booting people off lists is absurd on its face. The approach I see in your post indicates a much more practical approach based in a profound level of maturity. Let me know. beno -- http://mail.python.org/mailman/listinfo/python-list