Re: include statement
[EMAIL PROTECTED] wrote: > Thanks to all who took time to answer! > > >> > is it possible in python to include another python source file into the >> > current namespace, i.e.completely analogous to the #include statement >> > in C. > > [...] > >> Tell us why you are contemplating such a thing, and someone >> here will help you implement it the "Pythonic" way. > > My application has a configuration file where lots of variables are > set. (The configuration file is python source, so there is no > home-brewed parsing involved.) The configuration file is starting to > get quite large and unwieldy, so for this reason I would like to split > it in several files. > > I know I could do: > from configA import * > from configB import * > > But I felt that the import statemant was 'more' than I wanted. Maybe I > am just pedantic. Maybe you like execfile() which would allow you to collect the configuration files without the need for them to be reachable through the import mechanism. pattern = os.path.expanduser("~/.herron/config*.py") for fn in glob.glob(pattern): execfile(fn) # objects in the config*.py files now # share one namespace. Peter -- http://mail.python.org/mailman/listinfo/python-list
byte count unicode string
Marc 'BlackJack' Rintsch: >In <[EMAIL PROTECTED]>, willie wrote: >> # What's the correct way to get the >> # byte count of a unicode (UTF-8) string? >> # I couldn't find a builtin method >> # and the following is memory inefficient. >> ustr = "example\xC2\x9D".decode('UTF-8') >> num_chars = len(ustr)# 8 >> buf = ustr.encode('UTF-8') >> num_bytes = len(buf) # 9 >That is the correct way. # Apologies if I'm being dense, but it seems # unusual that I'd have to make a copy of a # unicode string, converting it into a byte # string, before I can determine the size (in bytes) # of the unicode string. Can someone provide the rational # for that or correct my misunderstanding? # Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Python Threading
Hello, Can anyone explain the main points in working with threads in Python. Why use threading and not Thread.I have read an article that i have to subclass the Thread class and override some function. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbe's re question
[EMAIL PROTECTED] wrote: > All I am after realy is to change this > > reline = re.line.split('instr', '/d$') > > into something that grabs any line with instr in it take all the > numbers and then grab any comment that may or may not be at the end of > the line starting with ; until the end of the line including white > spaces. > > [code] > def extractCsdInstrument (input_File_Name, output_File_Name, > instr_number): > "takes an .csd input file and grabs instr_number instrument and > creates output_File_Name" > f = open (input_File_Name , 'r') > f2 = open (output_File_Name, 'w') > instr_yes = 'false' # Python has built-in booleans ># Also, use sane naming: isInstr or hasInstr > > for line in f: > if "instr" in line: >if instr_yes == 'true': # Use the bool -- `if hasInstr:` >break > >reline = re.line.split('instr', '/d$') # ??? >number = int(reline[1]) > if number == instr_number: # Doesn't need to be 2 lines > instr_yes = "true": # the `:` is a syntax > error > if instr_yes = "true": >f2.write(f.line) # odd way of doing it... > > f.close() > f2.close() > > [/code] Did you read the HOWTO on regular expressions yet? It's included with the standard documentation, but here's a link: http://www.amk.ca/python/howto/regex/ Now, onto the issues: 1) The escape character is \, not /. Use "\d" to match a number. 2) I'm not sure I understand what you're trying to extract with your regex. As it is, the expression will return a list containing one item, a string identical to the line being matched up to, but not including, the first number. The rest of the line will be discarded. Try Kiki, a tool for testing regular expressions, before burying the expression in your code. 3) Python has built-in booleans: True and False, no quotes. Use them so that you don't get flamed on forums. 4) I don't claim to be a Python guru, but here's a massaged version of the function you gave: [code] def extractCsdInstrument (inputPath, outputPath, instrId): """ Takes a .csd file, grabs info for instrument ID and writes to file. """ src = open(inputPath, 'r') dst = open(outputPath, 'w') for line in src: if "instr" in line: info_comment = line.split(";", 1) # [info, comment] # Extract integers instrInfo = re.split(r"[^0-9]*", info_comment[0]) # Check the second number in the line if instrInfo[1] == str(instrId): dst.write(instrInfo.append(info_comment[1])) src.close() dst.close() [/code] I didn't check if this actually works, since I don't know what a .csd file looks like. There are of course other, better ways to do it, but hopefully this leads you in the right direction. 5) Please, read the documentation that came with your Python installation. Reading up on string methods etc. ahead of time will save you much more time than trying to slug through it. Also consider using a text editor with syntax highlighting; that will help catch most obvious syntax errors during coding. -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
willie wrote: > Marc 'BlackJack' Rintsch: > > >In <[EMAIL PROTECTED]>, willie wrote: > >> # What's the correct way to get the > >> # byte count of a unicode (UTF-8) string? > >> # I couldn't find a builtin method > >> # and the following is memory inefficient. > > >> ustr = "example\xC2\x9D".decode('UTF-8') > > >> num_chars = len(ustr)# 8 > > >> buf = ustr.encode('UTF-8') > > >> num_bytes = len(buf) # 9 > > >That is the correct way. > > > # Apologies if I'm being dense, but it seems > # unusual that I'd have to make a copy of a > # unicode string, converting it into a byte > # string, before I can determine the size (in bytes) > # of the unicode string. Can someone provide the rational > # for that or correct my misunderstanding? > You initially asked "What's the correct way to get the byte countof a unicode (UTF-8) string". It appears you meant "How can I find how many bytes there are in the UTF-8 representation of a Unicode string without manifesting the UTF-8 representation?". The answer is, "You can't", and the rationale would have to be that nobody thought of a use case for counting the length of the UTF-8 form but not creating the UTF-8 form. What is your use case? Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing 2.5 with 2.4?
"John Machin" <[EMAIL PROTECTED]> wrote: > 1. You need to set your path manually. A BAT file called pypath.bat > placed somewhere on your PATH and containing: > path c:\python%1;c:\python%1\scripts;%path% > might come in handy. Warning: this is best used once each time you open > up a command window; it's cumulative (Windows is not smart enough to > remove duplicate entries) and there is a an upper limit (I believe) on > the size of the PATH. Windows is only smart enough to avoid duplicate entries if you tell it to do that. e.g. PATH c:\python25;c:\python25\scripts;%PATH:c:\python25;c:\python25\scripts;=% will add the two Python 2.5 folders to the head of the path without duplicating them. -- http://mail.python.org/mailman/listinfo/python-list
Re: include statement
[EMAIL PROTECTED] wrote: > Thanks to all who took time to answer! > > >>> is it possible in python to include another python source file into the >>> current namespace, i.e.completely analogous to the #include statement >>> in C. > > [...] > >> Tell us why you are contemplating such a thing, and someone >> here will help you implement it the "Pythonic" way. > > My application has a configuration file where lots of variables are > set. (The configuration file is python source, so there is no > home-brewed parsing involved.) The configuration file is starting to > get quite large and unwieldy, so for this reason I would like to split > it in several files. > > I know I could do: > from configA import * > from configB import * > > But I felt that the import statemant was 'more' than I wanted. Maybe I > am just pedantic. Maybe... "import" is the very appropriate statement for what you want here IMVHO. I'd just put the config.py files into a 'config' directory, add an __init__.py, and put the 'from configX import *' there. Then in the app code, a simple 'import config', which allow acces to config vars via 'config.varname' (clean namespaces really improve maintainability). My 2 cents > Regards > > Joakim > -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
byte count unicode string
>willie wrote: >> Marc 'BlackJack' Rintsch: >> >> >In <[EMAIL PROTECTED]>, willie wrote: >> >> # What's the correct way to get the >> >> # byte count of a unicode (UTF-8) string? >> >> # I couldn't find a builtin method >> >> # and the following is memory inefficient. >> >> ustr = "example\xC2\x9D".decode('UTF-8') >> >> num_chars = len(ustr)# 8 >> >> buf = ustr.encode('UTF-8') >> >> num_bytes = len(buf) # 9 >> >That is the correct way. >> # Apologies if I'm being dense, but it seems >> # unusual that I'd have to make a copy of a >> # unicode string, converting it into a byte >> # string, before I can determine the size (in bytes) >> # of the unicode string. Can someone provide the rational >> # for that or correct my misunderstanding? >You initially asked "What's the correct way to get the byte countof a >unicode (UTF-8) string". > >It appears you meant "How can I find how many bytes there are in the >UTF-8 representation of a Unicode string without manifesting the UTF-8 >representation?". > >The answer is, "You can't", and the rationale would have to be that >nobody thought of a use case for counting the length of the UTF-8 form >but not creating the UTF-8 form. What is your use case? # Sorry for the confusion. My use case is a web app that # only deals with UTF-8 strings. I want to prevent silent # truncation of the data, so I want to validate the number # of bytes that make up the unicode string before sending # it to the database to be written. # For instance, say I have a name column that is varchar(50). # The 50 is in bytes not characters. So I can't use the length of # the unicode string to check if it's over the maximum allowed bytes. name = post.input('name') # utf-8 string # preferable if bytes(name) > 50: send_http_headers() display_page_begin() display_error_msg('the name is too long') display_form(name) display_page_end() # If I have a form with many input elements, # I have to convert each to a byte string # before i can see how many bytes make up the # unicode string. That's very memory inefficient # with large text fields - having to duplicate each # one to get its size in bytes: buf = name.encode('UTF-8') num_bytes = len(buf) # That said, I'm not losing any sleep over it, # so feel free to disregard any of this if it's # way off base. -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
John Machin wrote: > The answer is, "You can't", and the rationale would have to be that > nobody thought of a use case for counting the length of the UTF-8 form > but not creating the UTF-8 form. What is your use case? Playing DA here, what if you need to send the byte-count on a server via a header, but need the utf8 representation for the actual data? Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: why a main() function?
[EMAIL PROTECTED] wrote: > [EMAIL PROTECTED] wrote: >> I think I read a suggestion somewhere to wrap the code where a Python >> script starts in a main() function, so one has > > > >> What are the advantages of doing this? > > Others have stated all the good ones, so I'll state a slightly dumber > one for us part time amateur hackers :) > > If you start off writing all your python module inside a main function > then as you chop your code up into other functions (refactoring), the > code inside main is already at the proper indentation level for the new > top level functions. No more indenting it one level further to suit > the functions indentation. > That is also true if you start by putting all the main code inside an 'if __name__=="__main__":' block. Besides, how hard is it to select the code and hit tab or whatever the 'indent region' command is in your editor? FWIW, my scripts generally evolve through several stages. So looking at one I wrote recently I see that it started with a few lines at the outer level which quickly went inside a __name__=='__main__' block (so I could prod functions in the script interactively). Then as it grew larger the script moved into a main() function and some argument processing appeared in the __main__ block (and all the support functions disappeared into a separate module). Then I wanted some exception handling at the outer level so now I have the __main__ block containing outer level exception handling, and calling main() which does argument processing and calls script() which contains the original script. It may evolve further: main() is a bit too large at the moment, and I think I want to move the original script into another module with a command line argument to select between scripts. My point being that I don't have a hard and fast rule: I do whatever seems to make the code read clearly at the time. -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
MonkeeSage schrieb: > John Machin wrote: >> The answer is, "You can't", and the rationale would have to be that >> nobody thought of a use case for counting the length of the UTF-8 form >> but not creating the UTF-8 form. What is your use case? > > Playing DA here, what if you need to send the byte-count on a server > via a header, but need the utf8 representation for the actual data? So what - you need it in the end, don't you? The runtime complexity of the calculation will be the same - you have to consider each character, so its O(n). Of course you will roughly double the memory consumption - the original unicode being represented as UCS2 or UCS4. But then - if that really is a problem, how would you work with that string anyway? So you have to resort to slicing and computing the size of the parts, which will remedy that easily. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
"MonkeeSage" <[EMAIL PROTECTED]> wrote: > John Machin wrote: >> The answer is, "You can't", and the rationale would have to be that >> nobody thought of a use case for counting the length of the UTF-8 form >> but not creating the UTF-8 form. What is your use case? > > Playing DA here, what if you need to send the byte-count on a server > via a header, but need the utf8 representation for the actual data? Then you still need both the data and its length. John asked for an example where you need only the length and not the data itself. I guess you could invent something like inserting a string into a database which has fixed size fields, silently truncates fields which are too long and stores the strings internally in utf-8 but only accepts ucs-2 in its interface. Pretty far fetched, but if it exists I suspect that an extra utf-8 encoding here or there is the least of your problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
Duncan Booth <[EMAIL PROTECTED]> writes: > I guess you could invent something like inserting a string into a database > which has fixed size fields, silently truncates fields which are too long > and stores the strings internally in utf-8 but only accepts ucs-2 in its > interface. Pretty far fetched, but if it exists I suspect that an extra > utf-8 encoding here or there is the least of your problems. More direct would be to add an option to the http parser to return the utf8 received from the browser as a byte array still in utf8, instead of decoding it so that it needs to be re-encoded before insertion into the database. A lot of the time, the application doesn't need to look at the string anyway. -- http://mail.python.org/mailman/listinfo/python-list
Re: new string method in 2.5 (partition)
s = "There should be one -- and preferably only one -- obvious way to do it".partition('only one') print s[0]+'more than one'+s[2] ;) Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
OK, so the devil always loses. ;P Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
willie wrote: > >willie wrote: > >> Marc 'BlackJack' Rintsch: > >> > >> >In <[EMAIL PROTECTED]>, willie > wrote: > >> >> # What's the correct way to get the > >> >> # byte count of a unicode (UTF-8) string? > >> >> # I couldn't find a builtin method > >> >> # and the following is memory inefficient. > > >> >> ustr = "example\xC2\x9D".decode('UTF-8') > > >> >> num_chars = len(ustr)# 8 > > >> >> buf = ustr.encode('UTF-8') > > >> >> num_bytes = len(buf) # 9 > > >> >That is the correct way. > > >> # Apologies if I'm being dense, but it seems > >> # unusual that I'd have to make a copy of a > >> # unicode string, converting it into a byte > >> # string, before I can determine the size (in bytes) > >> # of the unicode string. Can someone provide the rational > >> # for that or correct my misunderstanding? > > >You initially asked "What's the correct way to get the byte countof a > >unicode (UTF-8) string". > > > >It appears you meant "How can I find how many bytes there are in the > >UTF-8 representation of a Unicode string without manifesting the UTF-8 > >representation?". > > > >The answer is, "You can't", and the rationale would have to be that > >nobody thought of a use case for counting the length of the UTF-8 form > >but not creating the UTF-8 form. What is your use case? > > # Sorry for the confusion. My use case is a web app that > # only deals with UTF-8 strings. I want to prevent silent > # truncation of the data, so I want to validate the number > # of bytes that make up the unicode string before sending > # it to the database to be written. > > # For instance, say I have a name column that is varchar(50). > # The 50 is in bytes not characters. So I can't use the length of > # the unicode string to check if it's over the maximum allowed bytes. What is the database API expecting to get as an arg: a Python unicode object, or a Python str (8-bit, presumably encoded in utf-8) ? > > name = post.input('name') # utf-8 string You are confusing the hell out of yourself. You say that your web app deals only with UTF-8 strings. Where do you get "the unicode string" from??? If name is a utf-8 string, as your comment says, then len(name) is all you need!!! *PLEASE* print type(name), repr(name) so that we can see what type it is!! If it says the type is str, then it's an 8-bit string, (presumably) encoded in utf-8. If it says the type is unicode, then please explain "web app that only deals with UTF-8 strings" ... > > # preferable > if bytes(name) > 50: > send_http_headers() > display_page_begin() > display_error_msg('the name is too long') > display_form(name) > display_page_end() > > # If I have a form with many input elements, > # I have to convert each to a byte string > # before i can see how many bytes make up the > # unicode string. That's very memory inefficient > # with large text fields - having to duplicate each > # one to get its size in bytes: They'd be garbage collected unless you worked very hard to hang on to them. How large is "large"? -- http://mail.python.org/mailman/listinfo/python-list
jpype package, could be path problem
Hello! Im a quite newbie in the python world. I have some problem with packages, i installed the jpype package according to its intructions. To test ive written: > python >>> import jpype everything worked correctly but when i wrote a short script: " from jpype import * jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') java.lang.System.out.println("hello world") shutdownJVM() " and tried to run it this's got: " Traceback (most recent call last): File "/home/kelemen/workspace/JPype/src/helloAgent.py", line 3, in ? jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') NameError: name 'jpype' is not defined " What would be the reason? thanks in advanced Viktor -- http://mail.python.org/mailman/listinfo/python-list
byte count unicode string
John Machin: >You are confusing the hell out of yourself. You say that your web app >deals only with UTF-8 strings. Where do you get "the unicode string" >from??? If name is a utf-8 string, as your comment says, then len(name) >is all you need!!! # I'll go ahead and concede defeat since you appear to be on the # verge of a heart attack :) # I can see that I lack clarity so I don't blame you. # By UTF-8 string, I mean a unicode object with UTF-8 encoding: type(ustr) >>> repr(ustr) "u'\\u2708'" # The database API expects unicode objects: # A template query, then a variable number of values. # Perhaps I'm a victim of arbitrary design decisions :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing 2.5 with 2.4?
Duncan Booth wrote: > "John Machin" <[EMAIL PROTECTED]> wrote: > > > 1. You need to set your path manually. A BAT file called pypath.bat > > placed somewhere on your PATH and containing: > > path c:\python%1;c:\python%1\scripts;%path% > > might come in handy. Warning: this is best used once each time you open > > up a command window; it's cumulative (Windows is not smart enough to > > remove duplicate entries) and there is a an upper limit (I believe) on > > the size of the PATH. > > Windows is only smart enough to avoid duplicate entries if you tell it > to do that. e.g. > > PATH c:\python25;c:\python25\scripts;%PATH:c:\python25;c:\python25\scripts;=% > > will add the two Python 2.5 folders to the head of the path without > duplicating them. Wow .. I didn't know that! What's the syntax? Something like %variablename[:oldtext=[newtext]]% ? Where is this documented? -- http://mail.python.org/mailman/listinfo/python-list
Re: jpype package, could be path problem
kelemen.viktor wrote: > everything worked correctly but when i wrote a short script: > " > from jpype import * > > jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') > java.lang.System.out.println("hello world") > shutdownJVM() > " > and tried to run it this's got: > > " > Traceback (most recent call last): > File "/home/kelemen/workspace/JPype/src/helloAgent.py", line 3, in ? > > jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') > NameError: name 'jpype' is not defined > " > > What would be the reason? Consider this: # bad style (potential name clash) from jpype import * startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') # that's better import jpype jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') # for long names of modules import jpype as jp jp.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') And see this: http://docs.python.org/tut/node8.html HTH, Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: Cheese Shop Registration error
Thank You all! :) I successfully registered and submited my first package :) Richard Jones wrote: > John Machin wrote: > > re.match("[A-Fa-f0-9]{8,8}", data.strip()) makes it plain what is > > intended ... > > Indeed, thanks. > > > Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: Cheese Shop Registration error
Thank You all! :) I successfully registered and submited my first package :) Richard Jones wrote: > John Machin wrote: > > re.match("[A-Fa-f0-9]{8,8}", data.strip()) makes it plain what is > > intended ... > > Indeed, thanks. > > > Richard -- http://mail.python.org/mailman/listinfo/python-list
Embedding Python and command history
Hi all! I'm embedding Python in my own C (or rather Ada, but via the C interface) program. Everything runs fine. But I have a small question regarding command history. Let's take the simplest example: #include int main(void) { Py_Initialize(); PyRun_InteractiveLoop(stdin, ""); Py_Finalize(); } When I compile this an run it, then I get control characters printed when I press cursor keys. When I start the "real" python interpreter, then I have command history via cursor keys. How can I make use of command history when embedded Python via PyRun_InteractiveLoop? Thanks a lot for your hints in advance! -- Stefan Bellon -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing 2.5 with 2.4?
[Duncan Booth] >> Windows is only smart enough to avoid duplicate entries if you tell it >> to do that. e.g. >> >> PATH c:\python25;c:\python25\scripts;%PATH:c:\python25;c:\python25\scripts;=% >> >> will add the two Python 2.5 folders to the head of the path without >> duplicating them. [John Machin[ > Wow .. I didn't know that! What's the syntax? Something like > %variablename[:oldtext=[newtext]]% > ? Yup. > Where is this documented? >From a DOS box (cmd.exe), enter set /? -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
willie wrote: > John Machin: > > >You are confusing the hell out of yourself. You say that your web app > >deals only with UTF-8 strings. Where do you get "the unicode string" > >from??? If name is a utf-8 string, as your comment says, then len(name) > >is all you need!!! > > > # I'll go ahead and concede defeat since you appear to be on the > # verge of a heart attack :) > # I can see that I lack clarity so I don't blame you. All you have to do is use terminology like "Python str object, encoded in utf-8" and "Python unicode object". > > # By UTF-8 string, I mean a unicode object with UTF-8 encoding: There is no such animal as a "unicode object with UTF-8 encoding". Don't make up terminology as you go. > > type(ustr) > > >>> repr(ustr) > "u'\\u2708'" Sigh. I suppose we have to infer that "ustr" is the same as the "name" that you were getting as post data. Is that correct? > > # The database API expects unicode objects: > # A template query, then a variable number of values. > # Perhaps I'm a victim of arbitrary design decisions :) And the database will encode those unicode objects as utf-8, silently truncating any that are too long -- just as Duncan feared? "Arbitrary" is not the word for it. Good luck! Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
willie wrote: > John Machin: > > >You are confusing the hell out of yourself. You say that your web app > >deals only with UTF-8 strings. Where do you get "the unicode string" > >from??? If name is a utf-8 string, as your comment says, then len(name) > >is all you need!!! > > > # I'll go ahead and concede defeat since you appear to be on the > # verge of a heart attack :) > # I can see that I lack clarity so I don't blame you. Could you please change your style of quoting/posting? It is extremely confusing - not only using a different character than > for citations, but also appearing to cite yourself while in fact it is your answer one reads. I'm all for expressing oneself and proving to be an individual - but communication can get tricky even with standardized manners of doing so, and there is no need to add more confusion. > # By UTF-8 string, I mean a unicode object with UTF-8 encoding: > > type(ustr) > > >>> repr(ustr) > "u'\\u2708'" You ARE confusing the hell out of yourself. There is no such thing as a unciode object with UTF-8 encoding. There are unicode objects. And there are byte-strings, which may happen to represent text encoded in utf-8. What you see above is a unicode code point literal - which is translated to a certain utf-8 string, that looks suspiciously alike because of the way utf-8 defines the mapping between the code-points of unicode to utf-8. But it still remains true: a unicode object is a unicode object. And has no encoding whatsoever! > # The database API expects unicode objects: > # A template query, then a variable number of values. > # Perhaps I'm a victim of arbitrary design decisions :) The same happens in java all the time, as java only deals with unicode strings. And for dealing with it, you also need to explicitly convert them to the proper encoded byte array. Unfortunate, but true. Diez -- http://mail.python.org/mailman/listinfo/python-list
ANN: eGenix mxODBC Zope Database Adapter 1.0.10 for Intel Mac OS X
ANNOUNCEMENT EGENIX.COM mxODBC Zope Database Adapter Version 1.0.10 Usable with Zope and the Plone CMS. Available for Zope 2.3 through 2.10 on Windows, Linux, Mac OS X, Solaris and FreeBSD INTRODUCTION The eGenix mxODBC Zope Database Adapter allows you to easily connect your Zope or Plone installation to just about any database backend on the market today, giving you the reliability of the commercially supported eGenix product mxODBC and the flexibility of the ODBC standard as middle-tier architecture. The mxODBC Zope Database Adapter is highly portable, just like Zope itself and provides a high performance interface to all your ODBC data sources, using a single well-supported interface on Windows, Linux, Mac OS X, Solaris and FreeBSD. This makes it ideal for deployment in ZEO Clusters and Zope hosting environments where stability and high performance are a top priority, establishing an excellent basis and scalable solution for your CMS. NEWS Our mxODBC Zope DA product is now available and supported on both Intel and PPC Mac OS X versions. UPGRADING If you have already bought mxODBC Zope DA 1.0.x licenses, you can use these license for the 1.0.10 version as well. There is no need to buy new licenses. The same is true for evaluation license users. MORE INFORMATION For more information on the mxODBC Zope Database Adapter, licensing and download instructions, please visit our web-site: http://zope.egenix.com/ You can buy mxODBC Zope DA licenses online from the eGenix.com shop at: http://shop.egenix.com/ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 20 2006) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! -- http://mail.python.org/mailman/listinfo/python-list
test, please ignore
This is a test message from your mailing list administrator. Please ignore. -- Sjoerd Mullender -- http://mail.python.org/mailman/listinfo/python-list
Re: SETUP - Introducing "setuptools" to a project without risk
Ilias Lazaridis wrote: > If I understood things right, setuptools extends the functionality of > distutils > > Thus replacing within a setup.py: > > from distutils.core import setup > > with > > try: > from setuptools import setup > except ImportError: > from distutils.core import setup > > should have the following behaviour: > > * does not change distutils functionality on any system (with or > without setuptools installed) > * adds setuptools functionality on a system with setuptools installed > > This is especially important to obtain the convenient "python setup.py > develop" command. > > Can someone confirm that the addition is non-critical? (I've not asked > on the setuptools list in order to get a neutral view of users). > > context: http://trac.edgewall.org/ticket/3743 After some conversation with the setuptools developer I've understood that I had wrong assumptions. setuptools alters the behaviour of the original distutils commands, thus the migration in such a way could cause problems. As suggested by the trac-team, the following is the workaround to use the setuptools develop command: python -c "import setuptools; execfile('setup.py')" develop - I think setuptools should be non-intrusive. All existent distutils commands should remain unaltered, exept if the user configures it differently. This would simplify migration to setuptools, as the project lead does not have to worry about potential problems. > -- > http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list
byte count unicode string
John Machin: >Good luck! Thank you for your patience and for educating me. (Though I still have a long way to go before enlightenment) I thought Python might have a small weakness in lacking an efficient way to get the number of bytes in a "UTF-8 encoded Python string object" (proper?), but I've been disabused of that notion. It's always a nice feeling when my language of choice withstands my nitpicking. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbe's re question
[EMAIL PROTECTED] wrote: > All I am after realy is to change this > > reline = re.line.split('instr', '/d$') > > into something that grabs any line with instr in it take all the > numbers and then grab any comment that may or may not be at the end of > the line starting with ; until the end of the line including white > spaces.. this is a corrected version from > > http://python-forum.org/py/viewtopic.php?t=1703 > > thanks in advance the hole routine is down below.. > > > > > > > [code] > def extractCsdInstrument (input_File_Name, output_File_Name, > instr_number): > > "takes an .csd input file and grabs instr_number instrument and > creates output_File_Name" > f = open (input_File_Name , 'r')#opens file passed > in to read > f2 = open (output_File_Name, 'w') #opens file passed > in to write > instr_yes = 'false' #set flag to false > > for line in f: #for through all > the lines > if "instr" in line: #look for instr in > the file >if instr_yes == 'true':#check to see if > this ends the instr block >break#exit the block > >reline = re.line.split('instr', '/d$') #error probily > split instr and /d (decimal number into parts) $ for end of line >number = int(reline[1]) #convert to a > number maybe not important > if number == instr_number:#check to see if > it is the instr passed to function > instr_yes = "true": #change flag to > true because this is the instr we want > if instr_yes = "true":#start of code to > copy to another file >f2.write(f.line) #write line to > output file > > f.close #close input file > f2.close > > [/code] > > Eric, From your problem description and your code it is unclear what exactly it is you want. The task appears to be rather simple, though, and if you don't get much useful help I'd say it is because you don't explain it very well. I believe we've been through this before and your input data is like this data = ''' ; ; test.csd - a Csound structured data file -W -d -o tone.wav ;optional section Before 4.10 ;these two statements check for After 4.08 ; Csound version 4.09 ; originally tone.orc sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 a1 oscil p4, p5, 1 ; simple oscillator out a1 endin ; originally tone.sco f1 0 8192 10 1 i1 0 1 2 1000 ;play one second of one kHz tone e Question 1: Is this your input? if yes: Question 1.1: What do you want to extract from it? In what format? if no: Question 1.1: What is your input? Question 1.2: What do you want to extract from it? In what format? Question 2: Do you need to generate output file names from the data? (One file per instrument?) if yes: Question 2.1: What do you want to make your file name from? (Instrument number?) Regards Frederic -- http://mail.python.org/mailman/listinfo/python-list
Re: RELEASED Python 2.5 (FINAL)
Anthony Baxter wrote: > It's been nearly 20 months since the last major release > of Python (2.4), and 5 months since the first alpha > release of this cycle, so I'm absolutely thrilled to be > able to say: > > On behalf of the Python development team > and the Python community, I'm happy to > announce the FINAL release of Python 2.5. Any chance the docs links could be fixed? The link on the front page still goes to 2.4.3 on docs.python.org, and the link from /download/releases/2.5/ goes to 2.6a0. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Request for elucidation: enhanced generators
A simple question - can anybody give a short example of how these work and what they are good for? I've read PEP 342 and the associated bit in the What's New section and it's still all Greek to me. The latter seems to focus on how to do it, rather than why you'd do it, so it doesn't aid the understanding too much. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: jpype package, could be path problem
Hi thanks for your suggestions ive modified the sample code " import jpype from jpype import * jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') java.lang.System.out.println("hello world") shutdownJVM() " and its working. It seems to be quite strange. What would be the difference between the two import? Viktor Rob Wolfe wrote: > Consider this: > > # bad style (potential name clash) > from jpype import * > startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') > > # that's better > import jpype > jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') > > # for long names of modules > import jpype as jp > jp.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') > > And see this: > http://docs.python.org/tut/node8.html > > HTH, > Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for elucidation: enhanced generators
Ben Sizer wrote: > A simple question - can anybody give a short example of how these work > and what they are good for? I've read PEP 342 and the associated bit in > the What's New section and it's still all Greek to me. The latter seems > to focus on how to do it, rather than why you'd do it, so it doesn't > aid the understanding too much. > Unti 2.5 the yield keyword could only be used to produce a value from a generator - it introduced a statement. Now the yield keyword can be used as an expression inside a generator, allowing you to send values into the generator by calling its .send() method. If you have no use case for this you are, as always, perfectly free to ignore it, as the majority of Python users may well choose to do. Your existing generators should continue to work. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: jpype package, could be path problem
kelemen.viktor wrote: > Hi > > thanks for your suggestions > > ive modified the sample code You've modified it incorrect. > " > import jpype > from jpype import * You should use "import jpype" OR "from jpype import *" (not recommended) but NOT BOTH. > jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea') > java.lang.System.out.println("hello world") > shutdownJVM() > " > > and its working. It seems to be quite strange. > What would be the difference between the two import? 1. "import jpype" This does not enter the name of the function startJVM defined in jpype directly in the current symbol table; it only enters the module name jpype there. Using the module name you can access the function like that: jpype.startJVM() 2. "from jpype import" This enters the name of the function startJVM in the currrent symbol table, so you can access the function just like that: startJVM() And have you read this: http://docs.python.org/tut/node8.html ? HTH, Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: high level, fast XML package for Python?
Martin v. Löwis wrote: >> Is there a standard xml package for Python? Preferably high-level, fast >> and that can parse in-file, not in-memory since I have to deal with >> potentially MBs of data. > > It seems that everybody is proposing libraries that use in-memory > representations. There is a standard xml package for Python, it's > called "xml" (and comes with the standard library). It contains a > SAX interface, xml.sax, which can parse files incrementally. note that the requirements included "high-level" and "fast"; sax is low-level, error-prone, and once you've finally fixed all the remaining bugs in your state machine, not that fast, really. -- http://mail.python.org/mailman/listinfo/python-list
Re: pprint: "...thank small children who sleep at night."
Brian L. Troutwine wrote: > Is the last sentence an obscure reference or in-joke? Can someone > explain it? I don't get it. do you have small kids? tried doing serious programming while they're still awake? -- http://mail.python.org/mailman/listinfo/python-list
Re: Single character input without pressing 'Enter'
unni.tallman wrote: > how can i read input from stdin, char by char, i want to get the > character as soon as it is entered, without having to press 'Enter' > after each character. related FAQ entries: http://pyfaq.infogami.com/how-do-i-get-a-single-keypress-at-a-time http://pyfaq.infogami.com/how-do-i-check-for-a-keypress-without-blocking (they should probably link to each other ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: CONSTRUCT - Adding Functionality to the Overall System
MonkeeSage wrote: > Ilias Lazaridis wrote: > > where do I place this function... > > The place where you want it to be. > > > ...thus it becomes available within class "Foo" and all other Classes? > > Anything defined in the top-level (i.e., the sys.modules['__main__'] > namespace) is accessible in every scope...but I assume you already know > that. no, I don't know it. how do I define something into the top-level namespace? I assume I could place it into the root-package of my project, into the __init__ function. But how do I place it within my computers python installation (the big init)? > You could also use a super-duper super class from which to derive all > your other classes, and add/replace any methods you want there: > > class lazaridis(object): ... I am aware of this technique. But I want to modify existent classes, without touching their code. > > Something like a central import? > > That would probably be the most logical thing to do. > > But again, I assume you already know all this, so why are you asking? > Is this part of the evaluation process? I am not evaluating Python, I've started using it: http://case.lazaridis.com/wiki/Lang http://dev.lazaridis.com/base - I've noticed some interesting code on you website: " class file(file): def reopen(self, name=None, mode='w', bufsize=None): ... fh = file('test.txt', 'rb') print fh # fh.reopen(mode='wb') " http://rightfootin.blogspot.com/2006/09/ruby-reopen.html does this mean that I can add a method to a class in a similar way with ruby? (by using class class-name(class-name): ) but the limitation is that I cannot do this with the python build-in types?: http://rightfootin.blogspot.com/2006/08/of-rocks-and-reptiles.html . -- http://mail.python.org/mailman/listinfo/python-list
How to measure memory footprint of Python objects?
Hello everybody, I try to solve the following problem: I have a python program that takes a lot of memory (>hundred Mb). I made an improvement (I hope) and I want to measure the gain (if possible on several platforms). I would like to be able to print the max memory taken during the run upon exiting my Python program (like I already do for the time taken to run). I can see the total process size of the Python process (Task manager on MS Win or Unix "ps" command) but that is not precise enough for me and also not convenient. I don't care about the python interpreter overhead, I'm interested only in the total size of Python objects allocated by my program. Is there a Python way to get that (meaning without resorting to non-portable, less precise OS features)? I would like to get that size at different given moments in time to make up a timeline of memory consumption. But, if that is too tricky, I would be happy to just get the maximum. Any suggestion welcome, Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to measure memory footprint of Python objects?
Neagu, Adrian wrote: > I have a python program that takes a lot of memory (>hundred Mb). > I can see the total process size of the Python process (Task manager on MS > Win or Unix "ps" command) but that is not precise enough for me I'm not sure those two statements are compatible, though. if your program is using hundreds of megabytes, surely kilobyte precision should be good enough for you ? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to measure memory footprint of Python objects?
"Neagu, Adrian" <[EMAIL PROTECTED]> writes: > I would like to get that size at different given moments in time to make up > a timeline of memory consumption. But, if that is too tricky, I would be > happy to just get the maximum. > > Any suggestion welcome, See the docs for the gc module. -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for elucidation: enhanced generators
Steve Holden wrote: > Ben Sizer wrote: > > A simple question - can anybody give a short example of how these work > > and what they are good for? I've read PEP 342 and the associated bit in > > the What's New section and it's still all Greek to me. The latter seems > > to focus on how to do it, rather than why you'd do it, so it doesn't > > aid the understanding too much. > > > Unti 2.5 the yield keyword could only be used to produce a value from a > generator - it introduced a statement. > > Now the yield keyword can be used as an expression inside a generator, > allowing you to send values into the generator by calling its .send() > method. > > If you have no use case for this you are, as always, perfectly free to > ignore it, as the majority of Python users may well choose to do. Your > existing generators should continue to work. But do you have an example of such a use case? That's what I'm missing here. Without ever having used proper coroutines elsewhere, I have no real way to appreciate their benefits without a good example. I don't think it's feasible to just ignore any new feature, as sooner or later you're going to encounter someone else's code that relies upon it. Hence why I'd rather not see all sorts of 'optional' extras added later (like type declarations and so on). -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: CONSTRUCT - Adding Functionality to the Overall System
Ilias Lazaridis wrote: > no, I don't know it. OK...so how do you evaluate a language when you don't know its basic operations? Hmmm, sounds fishy. > how do I define something into the top-level namespace? I assume I > could place it into the root-package of my project, into the __init__ > function. > > But how do I place it within my computers python installation (the big > init)? When you just say: def blah(): pass Now 'blah' function is in the top-level namespace, just like global variables. Or if it's in a different file, you'd say 'from blah import *'. You honestly don't know this?!?? > I am aware of this technique. > > But I want to modify existent classes, without touching their code. The only way to do this is to explicitly subclass the existent classes with your own class and modify what you want there in your subclass (see below), or use multiple inheritence as I suggested previously. > I've noticed some interesting code on you website: > > " > class file(file): > def reopen(self, name=None, mode='w', bufsize=None): > ... > > fh = file('test.txt', 'rb') > print fh # > fh.reopen(mode='wb') > " > http://rightfootin.blogspot.com/2006/09/ruby-reopen.html > > does this mean that I can add a method to a class in a similar way with > ruby? (by using class class-name(class-name): ) Basically, yes. In ruby you can reopen base classes; in python you can get the same effect by subclassing the base classes with the same name as the base class, then instantiating all your objects as that class. This is the exact same idea as a "super-duper super class" as I mentioned above. > but the limitation is that I cannot do this with the python build-in > types?: > > http://rightfootin.blogspot.com/2006/08/of-rocks-and-reptiles.html You can subclass buit-in types using the same name as the parent class. In fact here is what I use: ## my little library to make python more OO ## i.e., to get rid of the top-level junk... ## or at least to hide it behind some pretty ## object attributes :) ## ## YMMV - and don't complain if you don't ## like it; I wrote it for ME, not you ## ## Jordan Callicoat < [EMAIL PROTECTED] > ## some global methods so we can use them ## to set up the class methods def rpr(self): return str(repr(self)) def stri(self): return str(self) def inte(self): return int(self) def leng(self): return int(len(self)) def say(self): print(self) return self def joi(self, sep=''): return str(sep.join(self)) def ma(self, m): return list(map(m, self)) def filt(self, m): return list(filter(m, self)) def redu(self, m): return list(reduce(m, self)) ## now build all the subclasses class int(int): """ Wrapper class for +int+ Provided methods: str(), int(), repr(), say(), len(), plus(), minus(), times(), divided_by() """ def plus(self, i): return int(self + i) def minus(self, i): return int(self - i) def times(self, i): return int(self * i) def divided_by(self, i): return int(self / i) int.str = stri int.repr = rpr int.len = leng int.int = inte int.say = say class str(str): """ Wrapper class for +str+ Provided methods: str(), int(), repr(), say(), len(), plus(), times() """ def plus(self, s): return str(self + s) def times(self, i): return str(self * i) str.str = stri str.repr = rpr str.len = leng str.int = inte str.say = say class list(list): """ Wrapper class for +list+ Provided methods: str(), int(), repr(), say(), len(), plus(), times(), join() """ def plus(self, l): return list(self + l) def times(self, i): return list(self * i) list.str= stri list.repr = rpr list.len= leng list.say= say list.join = joi list.map= ma list.filter = filt list.reduce = redu class tuple(tuple): """ Wrapper class for +tuple+ Provided methods: str(), int(), repr(), say(), len(), plus(), times(), join() """ def plus(self, l): return tuple(self + l) def times(self, i): return tuple(self * i) tuple.str= stri tuple.repr = rpr tuple.len= leng tuple.say= say tuple.join = joi tuple.map= ma tuple.filter = filt tuple.reduce = redu class dict(dict): """ Wrapper class for +dict+ Provided methods: str(), int(), repr(), say(), len() """ pass dict.str = stri dict.repr = rpr dict.len = leng dict.say = say dict.join = joi ## done with the global methods, remove them del(rpr, stri, inte, say, joi, ma, filt, redu) ## show examples if called standalone if (__name__ == '__main__'): i = int(5) n = i + 5 n.say() i = i.times(5).divided_by(3).plus(2) i.str().int().str().repr().say() s = 'Tree' i = str(s) i = i.plus(' and dog\n').times(2) i.repr().say() def test(item): return '%s!' % item l = ['test', 'this', 'out', 'now'] i = list(l) i = i.times(2) i.join(' ').say() i.map(test).say() t = ('test', 'this', 'out', 'now') i = tuple(t) i = i.plus(('hi', 'there')) i.join('+').repr().sa
Using py2exe to wrap a service?
I have an app using active_directory.py and the std module asyncore in a Windows Service. Works perfectly! That is, until I try to use py2exe to create a standalone (need to avoid installing the entire Python etc. on the target system). When I try to start the installed Service, the system tells me it terminates prematurely and in the event log I find: The instance's SvcRun() method failed File "win32serviceutil.pyc", line 785, in SvcRun File "XXProxySvc.pyc", line 126, in SvcDoRun File "XXProxySvc.pyc", line 94, in setup File "D:\projects\XXProxy\DB.py", line 54, in loadFromAD File "active_directory.pyc", line 402, in search File "active_directory.pyc", line 398, in root File "active_directory.pyc", line 371, in AD File "active_directory.pyc", line 378, in _root File "win32com\client\__init__.pyc", line 73, in GetObject File "win32com\client\__init__.pyc", line 88, in Moniker pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None) The offending line is: import active_directory as AD ... for item in AD.search ("objectCategory='Person'"): ... I.e. the call to AD.search() is the entry point to the problem. The setup.py is (pretty straight forward..): from distutils.core import setup import py2exe class Target: def __init__(self, **kw): self.__dict__.update(kw) # for the versioninfo resources self.version = "0.9.0" self.company_name = "My Company" self.copyright = "My Company (c)" self.name = "FilterProxy" # a NT service, modules is required myservice = Target( # used for the versioninfo resource description = "AD Driven Mail Filter", # what to build. For a service, the module name (not the # filename) must be specified! modules = ["ProxySvc"] ) excludes = [] setup(options = {"py2exe": {# create a compressed zip archive #"compressed": 1, #"optimize": 2, "excludes": excludes } }, service=[myservice] ) 'elp! Plz! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to measure memory footprint of Python objects?
Paul Rubin wrote: > See the docs for the gc module. This is the first place I've checked. I see no useful info there about the actual size of the objects (bytes occupied in memeory). The closest thing to what I need is get_objects( ). Then I have to go over the list and do something with the objects. Wouldn't that be too slow? Thanks anyway, Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for elucidation: enhanced generators
Ben Sizer wrote: > But do you have an example of such a use case? here's what I think is the first published example that uses "yield" for co-routine-like behaviour: http://effbot.org/zone/asyncore-generators.htm that snippet uses a generator to implement a simple network protocol. the generator yields a status code when it needs more data from the framework, and the framework uses an instance variable (self.data) to pass information into the generator. Python 2.5 lets you eliminate the instance variable; instead of using an external shared variable, the framework can use "send" to pass data into the generator, and the generator can use ordinary expression syntax to pick it up. -- http://mail.python.org/mailman/listinfo/python-list
Nested Looping SQL Querys
I am back developing futher our Python/CGI based web application run by a Postgres DB and as per usual I am having some issues. It Involves a lot of Legacy code. All the actual SQL Querys are stored in the .py files and run in the .cgi files. I have the problem that I need to construct a row from two seprate SQL Querys, I have tried combining the two Querys but all that does is create a Query that returns nothing after a long period running. the first query results are delimited with [] and the second with {} I want my result to return [ val1 ] [ val2 ] [ val3 ] [ val4 ] { valA } { valB } unfortunatly when i put my second query in anywhere on the page its crashes and returns a Internal Server Error. the functions from the cmi file are below. def creationSQL(pubID, productCode, description, suppNo1, all): validQuery=0 if all: all=int(all[0]) all = cromwell.toString(all) sql='SELECT S.product_code, S.description, S.suppno1, P.discount_factor, S.status, S.list_price, S.offer_price, P.page_no, int8(P.oid), S.stock_qty ' sql=sql+'FROM (medusa.cmi_stockrec AS S INNER JOIN medusa.cmi_auxstockrec AS A ON S.product_code=A.product_code) LEFT JOIN medusa.cmi_pricing AS P ON S.product_code=P.product_code AND P.pub_id='+pubID+' ' sql=sql+'WHERE ' if productCode!='': sql=sql+cromwell.orSQL('S.product_code', productCode, 'ILIKE \'', '%\'', 1)+' AND ' print 'Product Code: '+productCode+'' validQuery=1 if description!='': sql=sql+' (upper(S.description) LIKE upper(\'%'+description+'%\')) AND ' print 'Description: '+description+'' validQuery=1 if suppNo1!='': sql=sql+' (upper(S.suppno1) LIKE upper(\'%'+suppNo1+'%\')) AND ' print 'Part No: '+suppNo1+'' validQuery=1 if all!=pubID: sql=sql+' (P.product_code IS NULL) AND ' sql=sql[:-4] sql=sql+' ORDER BY S.product_code' print '' if validQuery==1: return sql else: return '' def creationPubSQL(pubID, productCode, description, suppNo1, all, pubList, pubPageNo): validQuery=0 if all: all=int(all[0]) all = cromwell.toString(all) sql='SELECT Pl.product_code, S.description, S.suppno1, P.discount_factor, S.status, Pl.list_price, Pl.offer_price, P.page_no, int8(P.oid), Pl.page_no, S.stock_qty ' sql=sql+'FROM ((medusa.cmi_pricing AS Pl INNER JOIN medusa.cmi_stockrec AS S ON S.product_code=Pl.product_code) INNER JOIN medusa.cmi_auxstockrec AS A ON S.product_code=A.product_code) LEFT JOIN medusa.cmi_pricing AS P ON S.product_code=P.product_code AND P.pub_id='+pubID+' ' sql=sql+'WHERE Pl.pub_id='+pubList+' AND ' if productCode!='': sql=sql+cromwell.orSQL('Pl.product_code', productCode, 'ILIKE \'', '%\'', 1)+' AND ' print 'Product Code: '+productCode+'' validQuery=1 if description!='': sql=sql+' (upper(S.description) LIKE upper(\'%'+description+'%\')) AND ' print 'Description: '+description+'' validQuery=1 if suppNo1!='': sql=sql+' (upper(S.suppno1) LIKE upper(\'%'+suppNo1+'%\')) AND ' print 'Part No: '+suppNo1+'' validQuery=1 if pubPageNo!='': sql=sql+cromwell.orSQL('Pl.page_no', pubPageNo, '=\'', '\'', 1)+' AND ' print 'Publication Page No: '+pubPageNo+'' validQuery=1 if all!=pubID: sql=sql+' (P.product_code IS NULL) AND ' sql=sql[:-4] sql=sql+' ORDER BY Pl.product_code' print '' if validQuery==1: return sql else: return '' def stockdetailsSQL(productCode): validQuery=0 sql="SELECT (stkphys - stkalloc) as free_stock, stk_qty_wk, stkalloc, stkordq, r.fd_deliverydue " sql=sql+'FROM charisma.sk_stklfl LEFT JOIN progress.report_firstdelivery as r ON stkl_stockno = r.fd_sordstk ' sql=sql+'WHERE stkl_stockno = \''+productCode+'\' AND stkl_location = \'081\' ORDER BY stkl_stockno' validQuery=1 sql=sql[:-4] print '' if validQuery==1: return sql else: return '' The page code for the CGI file that genereates the tables #!/usr/bin/python # Creation Screen # MeDuSa - Marketing Data System # $Id: creation.cgi 54 2006-02-16 11:32:12Z [EMAIL PROTECTED] $ print 'Content-Type: text/html\n\n' import sys sys.stderr = sys.stdout from pyPgSQL import libpq import cgi import string import os import cmi import cromwell import hermes conn = hermes.db() # This will allow us to retrieve submitted form fields. cgiForm=cgi.FieldStorage() # Start as
Re: Embedding Python and command history
Stefan Bellon wrote: > int main(void) > { > Py_Initialize(); > PyRun_InteractiveLoop(stdin, ""); > Py_Finalize(); > } > How can I make use of command history when embedded Python via > PyRun_InteractiveLoop? Sorry to follow up my own posting ... I found that when I do "import readline" in this simple example, I have a working command history. When I do this in my real application, then I get the following: >>> import readline Traceback (most recent call last): File "", line 1, in ? ImportError: /usr/lib/python2.4/lib-dynload/readline.so: undefined symbol: PyExc_IOError Still experimenting what exactly is causing this. This application is not linked against libpython. But it loads a shared object at run time which is linked against libpython and which contains the call to PyRun_InteractiveLoop. But it looks like this "plugin" is not enough to make the symbols known to Python. If I add -lpython2.4 to the linker command when building the main application, then it works. But this is somewhat against what I was planning to achieve when using a plugin: independence of the main application from Python. Hm. -- Stefan Bellon -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for elucidation: enhanced generators
"Ben Sizer" <[EMAIL PROTECTED]> wrote: >> If you have no use case for this you are, as always, perfectly free to >> ignore it, as the majority of Python users may well choose to do. Your >> existing generators should continue to work. > > But do you have an example of such a use case? That's what I'm missing > here. Without ever having used proper coroutines elsewhere, I have no > real way to appreciate their benefits without a good example. One example which is commonly given is to implement a web application using continuations. So in Python terms a session is handled by a generator which yields a form to be sent back to the user and the user's response is sent in to the request using the generator's send method. State would be maintained in the generator. Whether this actually works well in practice (and how you handle things like a back button on the forms) is another matter. So very roughly your web code might look like this: def checkout(basket): orderOk = False while not OrderOk: order = (yield OrderForm(basket)) address = (yield AddressForm()) payment = (yield PaymentForm(order.total)) confirmation = (yield ConfirmationForm(order, address, payment)) orderOk = confirmation.confirmed placeOrder(order, address, payment) yield OrderPlacedPage() -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyglade, gtk, howto write more efficiently, and waste less code?
Thanks thomas!, i did it that way ;). maybe someone can help me with this, it seems simple, but i don`t know how to do it. I have: self.paths = ["","path1","path2","path3","path4","path5"] self.paths[1] = self.wTree.get_widget("path1") self.paths[2] = self.wTree.get_widget("path2") self.paths[3] = self.wTree.get_widget("path3") self.paths[4] = self.wTree.get_widget("path4") self.paths[5] = self.wTree.get_widget("path5") what about if i have 30 widgets? how can i "get" them all? .. variables variables? ¬¬ thanks everybody, good luck -- http://mail.python.org/mailman/listinfo/python-list
Re: How to measure memory footprint of Python objects?
Fredrik Lundh wrote: > Neagu, Adrian wrote: > > > I have a python program that takes a lot of memory (>hundred Mb). > > > I can see the total process size of the Python process (Task manager on MS > > Win or Unix "ps" command) but that is not precise enough for me > > I'm not sure those two statements are compatible, though. > > if your program is using hundreds of megabytes, surely kilobyte > precision should be good enough for you ? > Hi Fredrik, I'll be more precise. 1) Indeed, a few kilobytes are no problem for me. For example, if I have to write a small function to get my mem size and that function will allocate a few Python objects that will bias the end result, that's still OK. 2) The overhead of the Python execution engine in the total size of the process (C Python, JVM, ...) is more than just "a few kilobytes". As a last resort, this can be ignored for my purpose at hand (it is a constant in my comparison of different generations of my Python application) but it is not really nice (for example, I cannot meanigfully compare the memory footprint of only my application between platforms). 3) The real problem with OS-based size of process is the evolution over time. On MS Win for example, the size of the process is ever-growing (unless a MS specific consolidation function is called) leading to the fact that the size of the process and the actual size of the Python heap(s) has nothing to do with each other towards the end of the program. I believe that the max size of the process is an indication of the max size of the Python heap(s) but I'm not sure at all how good as an indication is that (what about different OSes?). Anyway, would it be much simpler (for the Python programmer) and much faster (at run-time) to surface this functionality in the sys module? Adrian. -- http://mail.python.org/mailman/listinfo/python-list
Re: include statement
[EMAIL PROTECTED] wrote: > Thanks to all who took time to answer! > > >>> is it possible in python to include another python source file into the >>> current namespace, i.e.completely analogous to the #include statement >>> in C. > > [...] > >> Tell us why you are contemplating such a thing, and someone >> here will help you implement it the "Pythonic" way. > > My application has a configuration file where lots of variables are > set. (The configuration file is python source, so there is no > home-brewed parsing involved.) The configuration file is starting to > get quite large and unwieldy, so for this reason I would like to split > it in several files. > > I know I could do: > from configA import * > from configB import * > > But I felt that the import statemant was 'more' than I wanted. Maybe I > am just pedantic. > > Regards > > Joakim > I might also suggest that you consider using ConfigParser module to store your "variables". If you are worried about performance, I can tell you that I use it to feed thousands of lines of configuration info into one of my applications (this app has 5 of these files) and ConfigParser handles them so quickly that performance is NOT a problem. The format of the file is easily understandable by nearly every user which means I don't have to worry with someone not understanding Python's syntax. If someone gets something wrong in a file that gets included, it is harder to take a sane default or handle the error than with ConfigParser. Just a suggestion that I hope helps. -Larry Bates or -- http://mail.python.org/mailman/listinfo/python-list
Re: Using py2exe to wrap a service?
[EMAIL PROTECTED] wrote: > I have an app using active_directory.py and the std module asyncore in > a Windows Service. > Works perfectly! > That is, until I try to use py2exe to create a standalone (need to > avoid installing the entire Python etc. on the target system). > > When I try to start the installed Service, the system tells me it > terminates prematurely > and in the event log I find: > The instance's SvcRun() method failed > File "win32serviceutil.pyc", line 785, in SvcRun > File "XXProxySvc.pyc", line 126, in SvcDoRun > File "XXProxySvc.pyc", line 94, in setup > File "D:\projects\XXProxy\DB.py", line 54, in loadFromAD > File "active_directory.pyc", line 402, in search > File "active_directory.pyc", line 398, in root > File "active_directory.pyc", line 371, in AD > File "active_directory.pyc", line 378, in _root > File "win32com\client\__init__.pyc", line 73, in GetObject > File "win32com\client\__init__.pyc", line 88, in Moniker > pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None) > > The offending line is: > import active_directory as AD > ... > for item in AD.search ("objectCategory='Person'"): > ... > > I.e. the call to AD.search() is the entry point to the problem. > > The setup.py is (pretty straight forward..): > from distutils.core import setup > import py2exe > > class Target: > def __init__(self, **kw): > self.__dict__.update(kw) > # for the versioninfo resources > self.version = "0.9.0" > self.company_name = "My Company" > self.copyright = "My Company (c)" > self.name = "FilterProxy" > > > # a NT service, modules is required > myservice = Target( > # used for the versioninfo resource > description = "AD Driven Mail Filter", > # what to build. For a service, the module name (not the > # filename) must be specified! > modules = ["ProxySvc"] > ) > > excludes = [] > setup(options = {"py2exe": {# create a compressed zip archive > #"compressed": 1, > #"optimize": 2, > "excludes": excludes > } > }, > service=[myservice] > ) > > 'elp! Plz! > You may want to post this on gmane.comp.python.py2exe also. I'm going to try to guess what the problem is, but it is a little hard to tell from here. py2exe does its best to find all the modules required to create the .exe. Sometimes modules do dynamic imports, etc. of modules that "fool" py2exe. I'm guessing that this is the case and that you will need to manually include the missing module. Most such errors seem to fall into this category. Hope this at least points you in the correct direction. -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for elucidation: enhanced generators
Ben Sizer wrote: ... > But do you have an example of such a use case? That's what I'm missing > here. I've been looking at this myself, trying to understand the point of coroutines. I believe that they boil down to generators which are able to take in data as well as provide it. A simple way of looking at it seems to be that a coroutine is a generator which can have its state changed whilst it is still active. A silly example to illustrate: # coroutine.py def stateful_generator(people): greeting = "Hello" for person in people: received = (yield greeting + " " + person) if received: greeting = received if __name__ == "__main__": people = ["bob", "henry", "jim-lad", "boney", "greebo", "badger"] gen = stateful_generator(people) print gen.next() # Hello bob print gen.next() # Hello henry print gen.send("Yo! ")# Yo! jim-lad print gen.next() # Yo! boney print gen.send("Meow ")# Meow greebo print gen.next() # Meow badger So you can change the behaviour of the coroutine whilst it is running. That's as far as I have got with them though - there are presumably many other uses of coroutines out there as I guess this use case could be simulated using generators and globals. -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for elucidation: enhanced generators
Duncan Booth wrote: > One example which is commonly given is to implement a web application using > continuations. So in Python terms a session is handled by a generator which > yields a form to be sent back to the user and the user's response is sent > in to the request using the generator's send method. State would be > maintained in the generator. Whether this actually works well in practice > (and how you handle things like a back button on the forms) is another > matter. > > So very roughly your web code might look like this: > > def checkout(basket): > orderOk = False > > while not OrderOk: >order = (yield OrderForm(basket)) >address = (yield AddressForm()) >payment = (yield PaymentForm(order.total)) >confirmation = (yield ConfirmationForm(order, address, payment)) >orderOk = confirmation.confirmed > > placeOrder(order, address, payment) > yield OrderPlacedPage() I too wonder about the back button. I am familiar with this reference about modal web servers, that you probably know: http://www.double.co.nz/scheme/modal-web-server.html In that case, the back button can be made to work since in Scheme there are full continuations and it is possibile to store the state at a given point in time and go back to that point later on (i.e. when the user press the back button). Python generators however are not full continuations and you cannot go back to a previous time. I remember I did some experiment and it was possible to solve the problem by generating a lot of closures and associating each closure to one state in the time and one page in the UI. But is was complicated enough and finally I ended up simply storing the values entered by the user in HTML hidden widgets. Sometimes the simplest solutions are the better ones ;) Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Mail Transaction Failed
The message contains Unicode characters and has been sent as a binary attachment. File attachment: document.msg.bat The file attached to this email was removed because the file name is not allowed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to condese my array
Robert Kern wrote: > Of course, code that I wouldn't get fired for would have a slightly greater > line > count and fewer one-letter variable names. Great :D! That one made me laugh! wildemar -- http://mail.python.org/mailman/listinfo/python-list
RE: Using py2exe to wrap a service?
[EMAIL PROTECTED] [... snip ...] | File "win32com\client\__init__.pyc", line 73, in GetObject | File "win32com\client\__init__.pyc", line 88, in Moniker | pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None) | | The offending line is: | import active_directory as AD | ... | for item in AD.search ("objectCategory='Person'"): Not infrequently -- and quite bizarrely -- "Invalid syntax" errors in COM sometimes come down to a mishandling of threading. To ask the obvious: do you have a pythoncom.CoInitialize () somewhere in your code? This is a bit invisible, because Services are inherently threaded, while you were probably running it before unthreaded. May not be the answer, but worth a try. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Using py2exe to wrap a service?
Tim Golden schrieb: > [EMAIL PROTECTED] > > [... snip ...] > > | File "win32com\client\__init__.pyc", line 73, in GetObject > | File "win32com\client\__init__.pyc", line 88, in Moniker > | pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None) > | > | The offending line is: > | import active_directory as AD > | ... > | for item in AD.search ("objectCategory='Person'"): > > Not infrequently -- and quite bizarrely -- "Invalid syntax" > errors in COM sometimes come down to a mishandling of threading. > To ask the obvious: do you have a pythoncom.CoInitialize () > somewhere in your code? > > This is a bit invisible, because Services are inherently > threaded, while you were probably running it before > unthreaded. > > May not be the answer, but worth a try. Maybe another possibility is that py2exe fails to include makepy generated modules. Could that lead to this error? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: newbe's re question
Frederic Rentsch wrote: > [EMAIL PROTECTED] wrote: > > All I am after realy is to change this > > > > reline = re.line.split('instr', '/d$') > > > > into something that grabs any line with instr in it take all the > > numbers and then grab any comment that may or may not be at the end of > > the line starting with ; until the end of the line including white > > spaces.. this is a corrected version from > > > > http://python-forum.org/py/viewtopic.php?t=1703 > > > > thanks in advance the hole routine is down below.. > > > > > > > > > > > > > > [code] > > def extractCsdInstrument (input_File_Name, output_File_Name, > > instr_number): > > > > "takes an .csd input file and grabs instr_number instrument and > > creates output_File_Name" > > f = open (input_File_Name , 'r')#opens file passed > > in to read > > f2 = open (output_File_Name, 'w') #opens file passed > > in to write > > instr_yes = 'false' #set flag to false > > > > for line in f: #for through all > > the lines > > if "instr" in line: #look for instr in > > the file > >if instr_yes == 'true':#check to see if > > this ends the instr block > >break#exit the block > > > >reline = re.line.split('instr', '/d$') #error probily > > split instr and /d (decimal number into parts) $ for end of line > >number = int(reline[1]) #convert to a > > number maybe not important > > if number == instr_number:#check to see if > > it is the instr passed to function > > instr_yes = "true": #change flag to > > true because this is the instr we want > > if instr_yes = "true":#start of code to > > copy to another file > >f2.write(f.line) #write line to > > output file > > > > f.close #close input file > > f2.close > > > > [/code] > > > > > Eric, > From your problem description and your code it is unclear what > exactly it is you want. The task appears to be rather simple, though, > and if you don't get much useful help I'd say it is because you don't > explain it very well. > I believe we've been through this before and your input data is > like this > >data = ''' >; > ; test.csd - a Csound structured data file > > > -W -d -o tone.wav > > >;optional section > Before 4.10 ;these two statements check for > After 4.08 ; Csound version 4.09 > > > > ; originally tone.orc > sr = 44100 > kr = 4410 > ksmps = 10 > nchnls = 1 > instr 1 > a1 oscil p4, p5, 1 ; simple oscillator > out a1 >endin > > > > ; originally tone.sco > f1 0 8192 10 1 > i1 0 1 2 1000 ;play one second of one kHz tone > e > > > > > Question 1: Is this your input? > if yes: > Question 1.1: What do you want to extract from it? In what format? > if no: > Question 1.1: What is your input? > Question 1.2: What do you want to extract from it? In what format? > Question 2: Do you need to generate output file names from the data? > (One file per instrument?) > if yes: >Question 2.1: What do you want to make your file name from? > (Instrument number?) > > > Regards > > Frederic I want to pass the file name to the subroutine and return a comment string if it is there maybe it should be simplier. I probily should have the option of grabbing the comment in other related routines. I am pretty ambitious with the main program. I did notice some code in tcl that would be usefull to the app If I compile it.. I am probily not ready for that though.. http://www.dexrow.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Using py2exe to wrap a service?
[Thomas Heller] | Tim Golden schrieb: | > [EMAIL PROTECTED] | > | > [... snip ...] | > | > | File "win32com\client\__init__.pyc", line 73, in GetObject | > | File "win32com\client\__init__.pyc", line 88, in Moniker | > | pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None) | > | | > | The offending line is: | > | import active_directory as AD | > | ... | > | for item in AD.search ("objectCategory='Person'"): | > | > Not infrequently -- and quite bizarrely -- "Invalid syntax" | > errors in COM sometimes come down to a mishandling of threading. | > To ask the obvious: do you have a pythoncom.CoInitialize () | > somewhere in your code? | > | > This is a bit invisible, because Services are inherently | > threaded, while you were probably running it before | > unthreaded. | > | > May not be the answer, but worth a try. | | Maybe another possibility is that py2exe fails to include makepy | generated modules. Could that lead to this error? Could easily be. I vaguely remember some similar problem with the WMI module, which I worked around by not doing a dynamic import in the end... or something. Don't think I've got the option here. (I wrote the active_directory module, in case it wasn't clear). TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: pprint: "...thank small children who sleep at night."
Brian L. Troutwine wrote: > thank small children who sleep at night. That seems like the kind of sentence that could become a tagline or something, and you just have to be in the know to understand where it comes from. :) -- http://mail.python.org/mailman/listinfo/python-list
Is it possible to change a picture resolution with Python?
Is it possible to change a picture resolution with Python? Let's say I have a picture with a resolution of 96 dpi and I would like to increase to 256dpi or higher. Thank you for your reply. LL -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace single character at given position
[EMAIL PROTECTED] wrote: > Martin Kulas: >> Are there better (faster) ways to achieve my goal? >> I have looked through the methods of type ``string'' >> but I have not found any appropriate method or function. [...] > A second way is to use a list of strings with len=1. Like this: idx = 1 s1 = "pxthon" l1 = list(s1) l1[idx] = 'y' > ... more processing on the elements of l1, then at the end: "".join(l1) > 'python' There is a MutableString class that would be a better approach: http://docs.python.org/lib/module-UserString.html Anyway, I bet that what Martin wants to do can be done by using only string methods :) -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: pprint: "...thank small children who sleep at night."
Brian L. Troutwine wrote: > The heading comment to pprint reads: > > # This is a simple little module I wrote to make life easier. I > didn't > # see anything quite like it in the library, though I may have > overlooked > # something. I wrote this when I was trying to read some heavily > nested > # tuples with fairly non-descriptive content. This is modeled very > much > # after Lisp/Scheme - style pretty-printing of lists. If you find it > # useful, thank small children who sleep at night. > > Is the last sentence an obscure reference or in-joke? Can someone > explain it? I don't get it. My guess is that he had to write a pretty printer so his cursing and general frustration and reading nasty nested tuples wouldn't wake the kids. -Adam -- http://mail.python.org/mailman/listinfo/python-list
Re: CONSTRUCT - Adding Functionality to the Overall System
MonkeeSage wrote: > Ilias Lazaridis wrote: >> no, I don't know it. > > OK...so how do you evaluate a language when you don't know its basic > operations? Hmmm, sounds fishy. The learning-process is an important part of the evaluation. >> how do I define something into the top-level namespace? I assume I >> could place it into the root-package of my project, into the __init__ >> function. >> >> But how do I place it within my computers python installation (the big >> init)? > > When you just say: > > def blah(): pass > > Now 'blah' function is in the top-level namespace, just like global > variables. Or if it's in a different file, you'd say 'from blah import > *'. You honestly don't know this?!?? I know how to define it: --- myBlahWithImport.py --- from mylib import blah if (__name__ == '__main__'): blah() --- end file --- what I dont know is, how to negate the need of the import statement. --- myBlah.py --- if (__name__ == '__main__'): blah() --- end file --- >> I am aware of this technique. >> >> But I want to modify existent classes, without touching their code. > > The only way to do this is to explicitly subclass the existent classes > with your own class and modify what you want there in your subclass > (see below), or use multiple inheritence as I suggested previously. > >> I've noticed some interesting code on you website: >> >> " >> class file(file): >> def reopen(self, name=None, mode='w', bufsize=None): >> ... >> >> fh = file('test.txt', 'rb') >> print fh # >> fh.reopen(mode='wb') >> " >> http://rightfootin.blogspot.com/2006/09/ruby-reopen.html >> >> does this mean that I can add a method to a class in a similar way with >> ruby? (by using class class-name(class-name): ) > > Basically, yes. In ruby you can reopen base classes; in python you can > get the same effect by subclassing the base classes with the same name > as the base class, then instantiating all your objects as that class. > This is the exact same idea as a "super-duper super class" as I > mentioned above. That's a part of the construct I was looking for. >> but the limitation is that I cannot do this with the python build-in >> types?: >> >> http://rightfootin.blogspot.com/2006/08/of-rocks-and-reptiles.html > > You can subclass buit-in types using the same name as the parent class. So, that's a 2nd part of the constrcut I was looking for. btw: from which class does "int" inherit? > In fact here is what I use: > > ## my little library to make python more OO > ## i.e., to get rid of the top-level junk... > ## or at least to hide it behind some pretty > ## object attributes :) > ## > ## YMMV - and don't complain if you don't > ## like it; I wrote it for ME, not you > ## > ## Jordan Callicoat < [EMAIL PROTECTED] > > > ## some global methods so we can use them > ## to set up the class methods ... (many code I'll review at a later point) > It's not the most "pythojnic" way to do things, but it works for me. > > Ps. I still have a hard time belieiving that after all the time you've > spent on comp.lang.lisp, comp.lang.ruby and comp.lang.python you still > don't understand these basic concepts...if that's really true, I would > never use your consulting service! "CONSTRUCT - Adding Functionality to the Overall System" This is not a basic concept. Although in smaltalk and ruby is very simple. But I've selected to use Python. . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get a Fix to an Abandoned Project?
Gregory Piñero wrote: > Say hello to pydelicious's new home ;-) > http://code.google.com/p/pydelicious/ > > -Greg Unless you are the original project's maintainer or have their consent on this it is usually bad form to name your fork the same thing as the original project. Granted, for something that has withered and died this may not be much of an issue, but it is good to know for future reference. -Adam -- http://mail.python.org/mailman/listinfo/python-list
Interested in a Python User Group in Porto/Portugal?
There is now a list to help put together such a group: http://groups.google.com/group/python-porto Regards, Pedro Lima PS. please forward this message to people you think that could be interested. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to change a picture resolution with Python?
Lad: > Is it possible to change a picture resolution with Python? > Let's say I have a picture with a resolution of 96 dpi and I would like > to increase to 256dpi or higher. "Resolution" is a too much overloaded word, from some point of view increasing the resolution of images is a very difficult thing, that may need deblurring, etc. So let's talk in a simpler way, about the len of the sides of the image measured in pixels. To increase such len, you can use PIL library, the resize method from image: http://www.pythonware.com/library/pil/handbook/image.htm This is some example code: from PIL import Image im = Image.open("1.jpg") nx, ny = im.size im2 = im.resize((int(nx*1.5), int(ny*1.5)), Image.BICUBIC) im2.save("2.png") Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: CONSTRUCT - Adding Functionality to the Overall System
(I don't believe I am responding to a notorious troll ...) One (bad) solution is to write in your sitecustomize.py the following: $ echo /usr/lib/python/sitecustomize.py import __builtin__ class Object(object): def debug(self): print 'some debug info' __builtin__.object = Object then you can do for instance >>> class C(object): pass >>> C().debug() some debug info All class inheriting from object will have the additional debug method. However I DO NOT RECOMMEND THIS SOLUTION FOR ANY SERIOUS WORK. For instance, it broke my IPython installation and I am pretty sure it will broke other things too. But it may work for debugging purposes, if not for production use, so I thought it was worth posting. Michee Simionato -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python-2.5 available at WebFaction
Hello everyone, I'm happy to announce that WebFaction have now installed Python-2.5 on all their servers. WebFaction (formerly Python-Hosting.com) support all the major Python web frameworks (Django, TurboGears, CherryPy, mod_python, Pylons, web.py, ...) People using Python CGI or Python-2.5-compatible application servers will be able to use all the new features of Python-2.5 for their website. Remi http://www.webfaction.com - Hosting for an agile web -- http://mail.python.org/mailman/listinfo/python-list
Trouble Passing Array of Strings (using Numeric) to C Extension Module
I am using Python 2.4.1 and Numeric 23.8 and running on Windows XP. I am passing a Numeric array of strings (objects) to a C Extension module using the following python code: import Numeric import TestDLL# my C Extension Module a = Numeric.array(['foo', 'bar'], 'O' ) print 'a =', a print 'type a[0] =', type(a[0]) print TestDLL.StringArrayIn( a ) And here is the relevent code from my C Extension module: static PyObject * _StringArrayIn( PyObject *self, PyObject *args ) { PyObject *pObject; // input array PyArrayObject *pArray; // contiguous array int iCount; int iStride; BOOL bString; if ( !PyArg_ParseTuple( args, "O", &pObject ) ) return NULL; if ( ( pArray = ( PyArrayObject * )PyArray_ContiguousFromObject( pObject, PyArray_OBJECT, 1, 1 ) ) == NULL ) return NULL; iCount = pArray->dimensions[0]; iStride = pArray->strides[0]; bString = PyString_Check( ( PyObject * )( pArray->data ) ); Py_DECREF( pArray ); return Py_BuildValue( "iiO", iCount, iStride, PyBool_FromLong( bString ) ); } static PyMethodDef Methods[] = { { "StringArrayIn", _StringArrayIn, METH_VARARGS, "" }, { NULL, NULL,0, NULL } /* Sentinel */ }; This code produces the following output: a = [foo bar ] type a[0] = (2, 4, False) The iCount and iStride values are as I expect (2 and 4 respectively), but performing a PyString_Check on the first array element (or more likely, what I think is the first array element) returns 'False'. BTW, the output above is from running the Python interpreter from the command line. When I run this code in IDLE, I get a GPF if I don't comment out the call to the PyString_Check function :-( What am I doing wrong here? -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested Looping SQL Querys
Fuzzydave wrote: (snip) """ pubID=cgiForm.getvalue('pubID') pubName=cgiForm.getvalue('pubName','Unknown Publication') sqlcheck1 = "SELECT pub_type FROM medusa.cmi_publication WHERE pub_id = '"+pubID+"'" overseas1 = conn.query(sqlcheck1) pubType = cmi.fetch_rows(overseas1) """ May we have the url where we can see this application in action ? I know some crackers that would be really pleased to mess with your production database... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to change a picture resolution with Python?
from > image: > http://www.pythonware.com/library/pil/handbook/image.htm > > This is some example code: > > from PIL import Image > im = Image.open("1.jpg") > nx, ny = im.size > im2 = im.resize((int(nx*1.5), int(ny*1.5)), Image.BICUBIC) > im2.save("2.png") > > Bye, bearophile, Thank you for your reply. But the above code increases size only , but not DPI resolutions( vertical nad horizontal).I need a higher vertical and horisontal resolutions. Any idea how to do that? Thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested Looping SQL Querys
Fuzzydave wrote: > I am back developing futher our Python/CGI based web application run by > a Postgres DB > and as per usual I am having some issues. It Involves a lot of Legacy > code. s/Legacy/Norwegian Blue/ -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested Looping SQL Querys
Bruno Desthuilliers wrote: > Fuzzydave wrote: > > (snip) > """ > pubID=cgiForm.getvalue('pubID') > pubName=cgiForm.getvalue('pubName','Unknown Publication') > > sqlcheck1 = "SELECT pub_type FROM medusa.cmi_publication WHERE pub_id = > '"+pubID+"'" > overseas1 = conn.query(sqlcheck1) > pubType = cmi.fetch_rows(overseas1) > """ > > May we have the url where we can see this application in action ? I know > some crackers that would be really pleased to mess with your production > database... > > In case Bruno's posting didn't make it obvious, your code is wide open to SQL injection exploits. Google is your friend. The correct way to remove such vulnerabilities is to use parameterized queries, giving the parameters as a tuple second argument to cursor.execute(). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to change a picture resolution with Python?
Lad: > But the above code increases size only , but not DPI resolutions( > vertical nad horizontal).I need a higher vertical and horisontal > resolutions. > Any idea how to do that? Do you need to overwrite the DPI tag contained in the header of a Jpeg/PNG image? Then you can probably find some library to modify such jpeg/png tags. (I think Photoshop is able to do it.) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
get process id...
How does one get the process id? Is there a method for windows and unix (mac os x etc...) -- http://mail.python.org/mailman/listinfo/python-list
Re: CONSTRUCT - Adding Functionality to the Overall System
Michele Simionato wrote: > (I don't believe I am responding to a notorious troll ...) > Believe it. You are. Ain't life a bitch? :-) > One (bad) solution is to write in your sitecustomize.py the following: > > $ echo /usr/lib/python/sitecustomize.py > import __builtin__ > > class Object(object): > def debug(self): > print 'some debug info' > > __builtin__.object = Object > > then you can do for instance > > class C(object): pass C().debug() > > some debug info > > All class inheriting from object will have the additional debug method. But sadly not the built-in types like int and str, which is what our trollish friend wants to do (for some reason best known to himself). > However I DO NOT > RECOMMEND THIS SOLUTION FOR ANY SERIOUS WORK. For instance, it broke my > IPython installation and I am pretty sure it will broke other things > too. > But it may work for debugging purposes, if not for production use, so I > thought it was worth > posting. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: get process id...
SpreadTooThin wrote: > How does one get the process id? > Is there a method for windows and unix (mac os x etc...) under linux, do: import os os.getpid() -- http://mail.python.org/mailman/listinfo/python-list
Python regular expression question!
I'm trying to do a whole word pattern match for the term 'MULTX-' Currently, my regular expression syntax is: re.search(('^')+(keyword+'\\b') where keyword comes from a list of terms. ('MULTX-' is in this list, and hence a keyword). My regular expression works for a variety of different keywords except for 'MULTX-'. It does work for MULTX, however, so I'm thinking that the '-' sign is delimited as a word boundary. Is there any way to get Python to override this word boundary? I've tried using raw strings, but the syntax is painful. My attempts were: re.search(('^')+("r"+keyword+'\b') re.search(('^')+("r'"+keyword+'\b') and then tried the even simpler: re.search(('^')+("r'"+keyword) re.search(('^')+("r''"+keyword) and all of those failed for everything. Any suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python regular expression question!
"unexpected" <[EMAIL PROTECTED]> writes: > I'm trying to do a whole word pattern match for the term 'MULTX-' > > Currently, my regular expression syntax is: > > re.search(('^')+(keyword+'\\b') \b matches the beginning/end of a word (characters a-zA-Z_0-9). So that regex will match e.g. MULTX-FOO but not MULTX-. Incidentally, in case the keyword contains regex special characters (like '*') you may wish to escape it: re.escape(keyword). -- Hallvard -- http://mail.python.org/mailman/listinfo/python-list
Leaks in subprocess.Popen
I'm using Python 2.4.3 for Win32. I was trying to run a few child processes simultaneously in separate threads and get their STDOUT, but the program was leaking memory and I found that it was because of subprocess operating in another thread. The following code works fine, but I get a leaking handle every second. You can see it in the task manager if you choose to see the column. Does anybody have a solution? Please help! import subprocess, time, thread def comm(command): run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = run.communicate() print out while 1: thread.start_new_thread(comm, ("dir",)) time.sleep(1) -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to change a picture resolution with Python?
> Thank you for your reply. > But the above code increases size only , but not DPI resolutions( > vertical nad horizontal).I need a higher vertical and horisontal > resolutions. > Any idea how to do that? The DPI is nothing an image contains by itself - it depends on the resolution of the rendering device! So - without knowing what DPI the output device produces, and which resolution the image was acquired in, you can't do anything. If you know these two quantities, you can scale the image by the appropriate amount. Bearophile suggested that there might be a DPI-information stored in the image itself. If so, it is hopefully the DPI the image was e.g. scanned in. But if you for example afterwards scaled it by half, this information must be altered accordingly, to reflect the changes. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: high level, fast XML package for Python?
Paul Boddie schrieb: >> It seems that everybody is proposing libraries that use in-memory >> representations. There is a standard xml package for Python, it's >> called "xml" (and comes with the standard library). It contains a >> SAX interface, xml.sax, which can parse files incrementally. > > What about xml.dom.pulldom? It quite possibly resembles ElementTree's > iterparse, or at least promotes event-style handling of XML information > using some kind of mainloop... Right; that also meets the criteria of being standard and not in-memory (nobody had mentioned it so far). Whether it is high-level and fast is in the eyes of the beholder (as they are relative, rather than absolute properties). Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested Looping SQL Querys
Dennis Lee Bieber wrote: [...] > # not conn.execute() ? That's what all the DB-API compliant adapters > use > > result = conn.execute(sql, params) > .execute() is a cursor method, not a connection method. Some DB API modules do implement it as a connection method, but that makes it impossible for several cursors to share the same connection (which is allowed by some modules). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: byte count unicode string
willie schrieb: > Thank you for your patience and for educating me. > (Though I still have a long way to go before enlightenment) > I thought Python might have a small weakness in > lacking an efficient way to get the number of bytes > in a "UTF-8 encoded Python string object" (proper?), > but I've been disabused of that notion. Well, to get to the enlightenment, you have to understand that Unicode and UTF-8 are *not* synonyms. A Python Unicode string is an abstract sequence of characters. It does have an in-memory representation, but that is irrelevant and depends on what microprocessor you use. A byte string is a sequence of quantities with 8 bits each (called bytes). For each of them, the notion of "length" exists: For a Unicode string, it's the number of characters; for a byte string, the number of bytes. UTF-8 is a character encoding; it is only meaningful to say that byte strings have an encoding (where "UTF-8", "cp1252", "iso-2022-jp" are really very similar). For a character encoding, "what is the number of bytes?" is a meaningful question. For a Unicode string, this question is not meaningful: you have to specify the encoding first. Now, there is no len(unicode_string, encoding) function: len takes a single argument. To specify both the string and the encoding, you have to write len(unicode_string.encode(encoding)). This, as a side effect, actually computes the encoding. While it would be possible to answer the question "how many bytes has Unicode string S in encoding E?" without actually encoding the string, doing so would require codecs to implement their algorithm twice: once to count the number of bytes, and once to actually perform the encoding. Since this operation is not that frequent, it was chosen not to put the burden of implementing the algorithm twice (actually, doing so was never even considered). HTH, Martin -- http://mail.python.org/mailman/listinfo/python-list
Do we need to delete "ImageDraw.Draw" after using it?
Hello all: I am looking the sample code posted on PIL website http://www.pythonware.com/library/pil/handbook/imagedraw.htm <> import Image, ImageDraw im = Image.open("lena.pgm") draw = ImageDraw.Draw(im) draw.line((0, 0) + im.size, fill=128) draw.line((0, im.size[1], im.size[0], 0), fill=128) del draw # === Why we should delete this object draw? # write to stdout im.save(sys.stdout, "PNG") # Is there any general rule that we must delete the object after using it? Thank you -Daniel -- http://mail.python.org/mailman/listinfo/python-list
unicode mystery/problem
Hi, I am using Python 2.4.3 on Fedora Core4 and "Eric3" Python IDE . Below mentioned code works fine in the Eric3 environment. While trying to start it from the command line, it returns: Traceback (most recent call last): File "pokus_1.py", line 5, in ? print str(a) UnicodeEncodeError: 'ascii' codec can't encode character u'\xc1' in position 6: ordinal not in range(128) == 8< = #!/usr/bin python # -*- Encoding: utf_8 -*- a= u'DISKOV\xc1 POLE' print a print str(a) == 8< = Even it looks strange, I have to use str(a) syntax even I know the "a" variable is a string. I am trying to use ChartDirector for Python (charts for Python) and the method "layer.addDataSet()" needs above mentioned syntax otherwise it returns an Error. layer.addDataSet(data, colour, str(dataName)) Thanks for your comments Petr Jakes -- http://mail.python.org/mailman/listinfo/python-list
Re: newbe's re question
[EMAIL PROTECTED] wrote: > Frederic Rentsch wrote: > >> [EMAIL PROTECTED] wrote: >> >>> All I am after realy is to change this >>> >>> reline = re.line.split('instr', '/d$') >>> >>> into something that grabs any line with instr in it take all the >>> numbers and then grab any comment that may or may not be at the end of >>> the line starting with ; until the end of the line including white >>> spaces.. this is a corrected version from >>> >>> http://python-forum.org/py/viewtopic.php?t=1703 >>> >>> thanks in advance the hole routine is down below.. >>> >>> >>> >>> >>> >>> >>> [code] >>> def extractCsdInstrument (input_File_Name, output_File_Name, >>> instr_number): >>> >>> "takes an .csd input file and grabs instr_number instrument and >>> creates output_File_Name" >>> f = open (input_File_Name , 'r')#opens file passed >>> in to read >>> f2 = open (output_File_Name, 'w') #opens file passed >>> in to write >>> instr_yes = 'false' #set flag to false >>> >>> for line in f: #for through all >>> the lines >>> if "instr" in line: #look for instr in >>> the file >>>if instr_yes == 'true':#check to see if >>> this ends the instr block >>>break#exit the block >>> >>>reline = re.line.split('instr', '/d$') #error probily >>> split instr and /d (decimal number into parts) $ for end of line >>>number = int(reline[1]) #convert to a >>> number maybe not important >>> if number == instr_number:#check to see if >>> it is the instr passed to function >>> instr_yes = "true": #change flag to >>> true because this is the instr we want >>> if instr_yes = "true":#start of code to >>> copy to another file >>>f2.write(f.line) #write line to >>> output file >>> >>> f.close #close input file >>> f2.close >>> >>> [/code] >>> >>> >>> >> Eric, >> From your problem description and your code it is unclear what >> exactly it is you want. The task appears to be rather simple, though, >> and if you don't get much useful help I'd say it is because you don't >> explain it very well. >> I believe we've been through this before and your input data is >> like this >> >>data = ''' >>; >> ; test.csd - a Csound structured data file >> >> >> -W -d -o tone.wav >> >> >>;optional section >> Before 4.10 ;these two statements check for >> After 4.08 ; Csound version 4.09 >> >> >> >> ; originally tone.orc >> sr = 44100 >> kr = 4410 >> ksmps = 10 >> nchnls = 1 >> instr 1 >> a1 oscil p4, p5, 1 ; simple oscillator >> out a1 >>endin >> >> >> >> ; originally tone.sco >> f1 0 8192 10 1 >> i1 0 1 2 1000 ;play one second of one kHz tone >> e >> >> >> >> >> Question 1: Is this your input? >> if yes: >> Question 1.1: What do you want to extract from it? In what format? >> if no: >> Question 1.1: What is your input? >> Question 1.2: What do you want to extract from it? In what format? >> Question 2: Do you need to generate output file names from the data? >> (One file per instrument?) >> if yes: >>Question 2.1: What do you want to make your file name from? >> (Instrument number?) >> >> >> Regards >> >> Frederic >> > > I want to pass the file name to the subroutine and return a comment > string if it is there maybe it should be simplier. I probily should > have the option of grabbing the comment in other related routines. I > am pretty ambitious with the main program. I did notice some code in > tcl that would be usefull to the app If I compile it.. I am probily > not ready for that though.. > > http://www.dexrow.com > > Eric, I'm beginning to enjoy this. I'm sure we'll sort this out in no time if we proceed methodically. Imagine you are a teacher and I am your student. This is a quiz. I have to take it and you need to explain to me the problem you want me to solve. If you don't explain it clearly, I will not know what I have to do and cannot do the quiz. If you answer my questions above, your description of the problem will be clear and I can take the quiz. Okay? Frederic -- http://mail.python.org/mailman/listinfo/python-list
Re: CONSTRUCT - Adding Functionality to the Overall System
George Sakkis wrote: > Ilias Lazaridis wrote: > > > I like to add a method "writeDebug(self, msg)" to all (or the most > > possible) classes in the system. > > > > How do I do this? > > > > * with new style classes > > * with old style classes > > Short answer: you can't do it for builtin or extension types: > >>> list.writeDebug = lambda msg: "You'd wish" > ... > TypeError: can't set attributes of built-in/extension type 'list' > > Longer asnwer: Make it a function instead of a method. This function > could try to call the respective method, and as a fallback it would > have hardcoded what to do for each supported class, something like: > > def writeDebug(obj, msg): > try: return obj.writeDebug(msg) > except AttributeError: > if isinstance(obj,list): > # list msg > elif isinstance(obj,tuple): > # tuple msg > ... > else: > # default object msg > > If you insist though that you'd rather not use functions but only > methods, tough luck; you're better off with Ruby. I insist on methods, and It seems that I stay with Python. The effort for me to rework python to become more OO is much lesser, than the effort I would have to rework Ruby to become more (this and that). http://case.lazaridis.com/wiki/Lang And I've already started to like 2 things on python: * the missing "end" statement and * (I don't believe I write this) enforced indentation. . -- http://mail.python.org/mailman/listinfo/python-list
Looking for a reports module/project
Hello, I'm working on a script to gather data from our servers and then present the data as part of daily maintenance. Pretty straight forward stuff. However one of the limitations of an earlier design was presentation of the data so I'm working to make this version's report much clearer. I hate to cut a bunch of single purpose code. Before I wander down this road too far I thought I'd ask if anyone else has found a good module or project for writing simple text reports with python. Thanks for the recommendations. John Purser -- http://mail.python.org/mailman/listinfo/python-list
Re: Do we need to delete "ImageDraw.Draw" after using it?
"Daniel Mark" <[EMAIL PROTECTED]> wrote: > Is there any general rule that we must delete the object after using > it? In general: if the object is not destroyed when it goes out of scope (but later) and uses precious resources [1], or if a special clean up is required, you should delete it explicitly. [1] like file handles -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
Re: new string method in 2.5 (partition)
Terry Reedy wrote: > "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in > message news:[EMAIL PROTECTED] >> Err... is it me being dumb, or is it a perfect use case for str.split ? > > s.partition() was invented and its design settled on as a result of looking > at some awkward constructions in the standard library and other actual use > cases. Sometimes it replaces s.find or s.index instead of s.split. In > some cases, it is meant to be used within a loop. I was not involved and > so would refer you to the pydev discussions. While there is the functional aspect of the new partition method, I was wondering about the following /technical/ aspect: Because the result of partition is a non mutable tuple type containing three substrings of the original string, is it perhaps also the case that partition works without allocating extra memory for 3 new string objects and copying the substrings into them? I can imagine that the tuple type returned by partition is actually a special object that contains a few internal pointers into the original string to point at the locations of each substring. Although a quick type check of the result object revealed that it was just a regular tuple type, so I don't think the above is true... --Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Python regular expression question!
> \b matches the beginning/end of a word (characters a-zA-Z_0-9). > So that regex will match e.g. MULTX-FOO but not MULTX-. > So is there a way to get \b to include - ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a reports module/project
John Purser wrote: > Hello, > > I'm working on a script to gather data from our servers and then present > the data as part of daily maintenance. Pretty straight forward stuff. > However one of the limitations of an earlier design was presentation of > the data so I'm working to make this version's report much clearer. I > hate to cut a bunch of single purpose code. Before I wander down this > road too far I thought I'd ask if anyone else has found a good module or > project for writing simple text reports with python. > > Thanks for the recommendations. > > John Purser > wxPython and htmlgen -- http://mail.python.org/mailman/listinfo/python-list
Re: Mechanoid Web Browser - Recording Capability
You can try SWExplorerAutomation (SWEA) (http:\\webunittesting.com). It works very well with the password protected sites. SWEA is .Net API, but you can use IronPython to access it. Seymour wrote: > I am trying to find a way to sign onto my Wall Street Journal account > (http://online.wsj.com/public/us) and automatically download various > financial pages on stocks and mutual funds that I am interested in > tracking. I have a subscription to this site and am trying to figure > out how to use python, which I have been trying to learn for the past > year, to automatically login and capture a few different pages. > I have mastered capturing web pages on non-password sites, but am > struggling otherwise and have been trying to learn how to program the > Mechanoid module (http://cheeseshop.python.org/pypi/mechanoid) to get > past the password protected site hurdle. > > My questions are: > 1. Is there an easier way to grab these pages from a password protected > site, or is the use of Mechanoid a reasonable approach? > 2. Is there an easy way of recording a web surfing session in Firefox > to see what the browser sends to the site? I am thinking that this > might help me better understand the Mechanoid commands, and more easily > program it. I do a fair amount of VBA Programming in Microsoft Excel > and have always found the Macro Recording feature a very useful > starting point which has greatly helped me get up to speed. > > Thanks for your help/insights. > Seymour -- http://mail.python.org/mailman/listinfo/python-list
How to evaluate the memory usage of a python program?
Hello all: I have a python program and would like to find out the maximum memory used by this program. Does Python provide such module so I could check it easily? Thank you -Daniel -- http://mail.python.org/mailman/listinfo/python-list