Re: text editor suggestion?
John Salerno <[EMAIL PROTECTED]> wrote: > Ok, I know it's been asked a million times, but I have a more specific > question so hopefully this won't be just the same old post. I've tried a > few different editors, and I really like UltraEdit, but it's > Windows-only and I'm working more on Linux nowadays. > > Here are my criteria: > > 1. syntax highlighting (highly customizable) > 2. auto/smart indenting > 3. ability to run script > 4. light-weight text editor, not an IDE > 5. cross-platform (not really necessary, but nice) > > That's pretty much all I need. It's nice when you can customize a bunch > of other stuff too, but those are the most important. > > I've tried vim, but I really don't feel like taking the time to learn > how to use it, given that I just like to casually program (not to > mention that I prefer to use the mouse when navigating a document > sometimes). Vim is rather nice once you know it, but i can understand that not everyone has the time to learn it. There is Cream[1] which is supposed to be a more modern configuration of VIM. I also remember using JED[2] for a while, but i can't remember the features of it well, so i can't say if they fullfill your requirements or not. [1] http://cream.sourceforge.net/ [2] http://www.jedsoft.org/jed/ -- setrodox -- http://mail.python.org/mailman/listinfo/python-list
Get paid to post in forums..
myLot promises to pay as you talk on its discussion boards. You can post and reply to whatever topic that you like. to join: http://www.mylot.com/?ref=blogger1 The following is taken from their website: ** How does this work? We have implemented a system to give everyone who uses the internet the ablity to make money. The idea is pretty simple - if you contribute to the myLot Community - whether it is by posting a new discussion, responding to a current discussion, commenting on a current discussion, or referring friends, you earn money. Our goal is to provide internet users a place to earn money using the web on a day to day basis and provide access to information they need. We pay each and every member of myLot based on their level of activity. As stated previously all you need to do is sign up for a myLot account and we do the rest. How do I set it up? We can't stress to you enough how simple the set up process is, all you need to do to start earning is sign up for a myLot account and become a user. How do I get Paid? Get paid monthly with minimum account balance of $10 and carry forward of unpaid amounts. All payments will be made via PayPal. All users will be required to have a valid PayPal Premier account. Click here to learn how to sign up for a PayPal Premier account. What can I do to increase my earnings? What an excellent question, and one we hope every myLot user will ask. Use myLot, post discussions, respond to discussions. Post quality content. For example, generate discussions that engage other users and provide insightful responses and comments to other users discussions to further the topic. Refer friends. For each person you send to myLot you will receive 25% of their earnings. How do I refer friends? All myLot users are automatically eligible to make money by referring new users to myLot. Invite friends, family, new acquaintances, forum buddies, or whomever you wish. You will receive 25% of their earnings. I own a website. What tools are available for me to promote myLot? Right now, the best available tool is our JavaScript feed. We will be adding more tools in the near future. Click here to find out how to integrate myLot content into your website (and get paid at the same time!) with our JavaScript feed. In general, by appending ?ref=username to the end of any myLot page, your myLot referrals will be tracked to your user account. Be creative. We're here to help you. The more money you make, the faster we grow, so we're in this together! What are the limitations? As far as we can see, there really are no limitations. You must have a myLot account to start. You get paid for your activity so it is up to you as to how much time and effort you put into this program. If you contribute you will earn money! Why does myLot reward its users financially? We believe users are the most valuable asset to the longevity of any website so why only provide them with a service, why not reward them financially? How do I calculate my earnings? Its very simple, earnings equal discussion activity plus user referrals. You will be able to see both your referral earnings and discussion activity earnings each time you sign into myLot. The two will be added together for your total earnings. -- http://mail.python.org/mailman/listinfo/python-list
PIL problem: IOError: cannot identify image file
Hi, I installed the newest available PIL (1.1.5 for Python 2.4) from their site, but cannot seem to open any files. The following from PIL import Image i = Image.open(file('c:\\image2.png')) results in File "C:\Program Files\Python24\lib\site-packages\PIL\Image.py", line 1745, in open raise IOError("cannot identify image file") IOError: cannot identify image file for any graphics file I've tried. Anyone know what's wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the ascii code of Chinese characters?
Gerhard Fiedler wrote: >> No. ASCII characters range is 0..127 while Unicode characters range is >> at least 0..65535. > > Actually, Unicode goes beyond 65535. you may want to look up "at least" in a dictionary. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the ascii code of Chinese characters?
many_years_after wrote: > Well, people may input from keyboard. They input some Chinese > characters, then, I want to create a number. The same number will be > created if they input the same Chinese characters. assuming you mean "code point" rather than "ASCII code" (ASCII is a specific encoding that *doesn't* include Chinese characters), "ord" is what you want: char = read_from_some_input_device() code = ord(char) see: http://pyref.infogami.com/ord -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the ascii code of Chinese characters?
In message <[EMAIL PROTECTED]>, Fredrik Lundh wrote: > Gerhard Fiedler wrote: > >>> No. ASCII characters range is 0..127 while Unicode characters range is >>> at least 0..65535. >> >> Actually, Unicode goes beyond 65535. > > you may want to look up "at least" in a dictionary. Maybe you need to do the same for "actually". -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL problem: IOError: cannot identify image file
Doh! Apparently Image.open() wants a path, not a file. So i = Image.open('c:\\image2.png') works fine. -- http://mail.python.org/mailman/listinfo/python-list
Re: Permission Denied
In message <[EMAIL PROTECTED]>, AlbaClause wrote: > Then, to execute the file from from the shell prompt, I had to create a > 'bin' directory in my home folder, cuz I didn't want to litter > my /usr/local/bin folder with useless Python scripts. Executable files can be kept anywhere, you don't need a special directory for them. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter btn visual state with tkMessageBox
<[EMAIL PROTECTED]> Wrote: | | Hendrik van Rooyen wrote: | > <[EMAIL PROTECTED]> wrote: | > | > To: | > | > | > | why is the button sunken when called through a bind method, and not | > | with the command attribute? | > | Thank you! | > | | > | | > | ## Cut'nPaste example | > | from Tkinter import * | > | import tkMessageBox | > | | > | class Vue(object): | > | def __init__(self): | > | self.root=Tk() | > | self.root.title("test button visual state") | > | self.b1=Button(self.root,text="tkMessageBox.showinfo with bind | > | :-(") #,command=self.showMsg) | > | self.b1.bind("",self.showMsg) | > | > 8<--- | > | > change this to : | > | >self.b1.bind("",self.showMsg) | > | > Problem is that a button "sinks in" when you press it and "springs back" when | > you release it... | > | > and the "Button" leaves it sunken - because when you release, the control is | > no longer there | > | > - Hendrik | Thanks Hendrik - is the command attribute connected to the bindable | events? | jm I don't have a clue - you are either asking about advanced magic here, or I don't understand your question - I believe the lower level routines are common, but I don't *Know* this - so its a pity that some people who shall be nameless have beaten their brains out in a thread about a directory name here.. You may have noticed that there is another subtle bug with what I have suggested to you - when you press the offending button, then move the mouse to move the cursor off the screen button, - the button "springs back" as expected - but then when you release the mouse button, off the screen button, the call back is done anyway, instead of being cancelled when the cursor moves off the screen button. - for the command case, the sequence is different, and the call back is done only if the release is done on the screen button... - But this may just be my setup - does yours do the same? I don't know how to fix that - you could look at sequences of events - button push followed by release - But I doubt whether this will help, as its doing something like that anyway (haven't tried it) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Rhamphoryncus wrote: > > It's worthwhile to note that the use of + as the concatenation operator > is arbitrary. It could just have well been | or &, and has no > relationship with mathematically addition. The effect of the string concatenation operator is only secondary. Secondary to the use of the word sum; and what could be 'reasonably' concieved as sum's effect on non-numeric types. > > It's also worth stressing (not in response to your post, but others) > that sum([[1],[2],[3]], []) is just as bad as attempting to sum > strings, both conceptually (it's not mathematical addition) Unfortunately, the words sum and summation are linked to other words that are commonly used to describe what is happening to the numders, the lists, and the strings. Words such as accumulate, concatenate, aggregate, collect, assemble, as well as add. > and performance-wise. Don't do it. :) Amen to that. > I believe the prefered method to flatten a list of lists is this: > > shallow = [] > for i in deep: > shallow.extend(i) > > Yes, it's three lines. It's also very easy to read. reduce() and > sum() are not. I'd like to squeeze in the listcomp version, not because it is one line shorter, but because I, and maybe others prefer short listcomps such as the folowing: shallow = [] [shallow.extend(i) for i in deep] -Pad. -- http://mail.python.org/mailman/listinfo/python-list
Re: Permission Denied
Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, AlbaClause wrote: > >> Then, to execute the file from from the shell prompt, I had to create a >> 'bin' directory in my home folder, cuz I didn't want to litter >> my /usr/local/bin folder with useless Python scripts. > > Executable files can be kept anywhere, you don't need a special directory > for them. Yes, I know, but if you want to just enter the filename at the shell prompt, the file has to be somewhere that it can be found. Otherwise you get the dreaded "command not found" error. Unless I'm doing something wrong? -- -- There are several things that I will never be: * I will never be attracted to females. * I will never enjoy the company of others. Exactly how these realities bode for my enemy, is not of my concern. -- http://mail.python.org/mailman/listinfo/python-list
Re: text editor suggestion?
On Sat, 19 Aug 2006 02:06:15 -0400, John Salerno <[EMAIL PROTECTED]> wrote: > Ben Finney wrote: > >> The two big names in text editing, Vim and Emacs, will both meet these >> criteria easily. They also have the advantage that you'll find one or >> the other, or both, on just about any Unix system intended for use by >> a programmer. And they're installable on Windows, and they will be ported to anything you're likely to encounter, for the rest of your life. >> There is also an enormous amount of support for both these editors, >> for all manner of text editing tasks, available online. It's a good >> idea to learn at least one of them very well, rather than learn a >> bunch of less-popular editors for specific tasks. That's an important point, IMHO. At least if you're living in Unix, plain old text editing is one of the most common tasks you do, and you rarely end up in situations where you're forced to use domain-specific editors (except when using web applications, where you are often limited to the text editing facilities of your web browser). I usually don't like the idea of becoming addicted to one simgle program, but I make an exception for text editing. I'm so much more productive in emacs than anywhere else, and the things I learn while (say) programming in Python translate directly to writing documentation, writing C code, or massaging and browsing large data sets. > I'd really like to learn vim, but I spent days just trying to figure out > how to get the syntax highlighting and indentation working, where these > settings are and how to edit them, and it still doesn't work for me. That's to be expected, and to be honest, you'd have the same problem with the editor I'd suggest, emacs. I've accepted that there are huge areas of emacs that I don't know and which would be useful to me if I had known them. It took almost ten years to discover dabbrev-expand, and I only found out about open-rectangle last week. And noone can tell me /which/ features I'm missing, because everyone uses their editor in a different way. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Easy Validators
Sometimes it's good to check things while working on them. This seems like a good way to do that. You could probably put these in a module and just import them. from validators import * I'm interested if anyone can think of ways to improve this further. Each validator consists of an assertion with an error message if the assertion fails. The validator arguments can include an extra argument to check the return value. Less than the number of arguments is ok. Any unspecified arguments are not checked. Use Any to not check previous arguments in a list. (see the examples at the end) Cheers, Ron # - Some Simple Validators. def Any(arg): pass def IsNumber(arg): assert type(arg) in (int, long, float), \ "%r is not a number" % arg def IsInt(arg): assert type(arg) in (int, long), \ "%r is not an Int" % arg def IsFloat(arg): assert isinstance(arg, float), \ "%r is not a flaot" % arg def IsLong(arg): assert isinstance(arg, long), \ "%r is not a long integer" % arg def IsString(arg): assert type(arg) in (str, unicode), \ "%r is not a string type" % arg def InRange(start, stop): def inrange(arg): assert start <= arg <= stop, \ "%r is not in range %r through %r" % (arg, start, stop) return inrange def InSet(list_): s = set(list_) def inset(arg): assert arg in s, \ "%r is not in %r" % (arg, s) return inset def LessThan(value): def lessthan(arg): assert arg < value, \ "%r is not less than %r." % (arg, value) return lessthan def MoreThan(value): def morethan(arg): assert arg > value, \ "%r is not more than %r." % (arg, value) return morethan def IsEven(arg): assert arg % 2 == 0, \ "%r is not even" % arg def IsOdd(arg): assert arg % 2 == 1, \ "%r is not odd" % arg def IsPositive(arg): assert arg >= 0, \ "%r is not positive" % arg def IsNegative(arg): assert arg < 0, \ "%r is not negative" % arg def IsTrue(arg): assert arg is True, \ "%r is not True" % arg def IsFalse(arg): assert arg is False, \ "%r is not False" % arg # - The validator decorator. def validate(*types): """ check arguments + return value against types given. """ def check_accepts(f): def new_f(*args, **kwds): assert len(types) <= len(args)+1, \ "Validators exceed arg count + return value." for (a, t) in zip(args, types): t(a) result = f(*args, **kwds) if len(types)>len(args): types[-1](result) return result new_f.func_name = f.func_name return new_f return check_accepts # -- Examples to play around with. @validate(Any, IsInt, IsEven) def add(a, b): return a + b @validate(InRange(1,6), InRange(1,6), LessThan(19)) def mul(a, b): return a * b # they stack too @validate(IsInt, IsInt) @validate(MoreThan(10),LessThan(10)) @validate(Any, IsPositive) def sub(a, b): return a - b @validate(IsString, IsString) def addstr(a, b): return a + b print add(3.0, 5) print mul(3, 6) print sub(11, 9) print addstr('Hello ', 'World') -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Paddy wrote: > Rhamphoryncus wrote: > > > > > It's worthwhile to note that the use of + as the concatenation operator > > is arbitrary. It could just have well been | or &, and has no > > relationship with mathematically addition. > > The effect of the string concatenation operator is only secondary. > Secondary to the use of the word sum; and what could be 'reasonably' > concieved as sum's effect on non-numeric types. > > > > It's also worth stressing (not in response to your post, but others) > > that sum([[1],[2],[3]], []) is just as bad as attempting to sum > > strings, both conceptually (it's not mathematical addition) > > Unfortunately, the words sum and summation are linked to other words > that are commonly used to describe what is happening to the numders, > the lists, and the strings. > Words such as accumulate, concatenate, aggregate, collect, assemble, as > well as add. String concatenation and numeric addition only group together under the most vague of english terms, "putting things together". String concatenation violates many mathematical properties of addition/summation, and simply isn't related. It is unfortunate that many languages (including python) promote the confusion by using + for a "put things together" operator, ie both mathematical addition and string concatenation. > > I believe the prefered method to flatten a list of lists is this: > > > > shallow = [] > > for i in deep: > > shallow.extend(i) > > > > Yes, it's three lines. It's also very easy to read. reduce() and > > sum() are not. > > I'd like to squeeze in the listcomp version, not because it is one line > shorter, but because I, and maybe others prefer short listcomps such as > the folowing: > > shallow = [] > [shallow.extend(i) for i in deep] I'm sure this has been mentioned before, but listcomps are for when you want to store the list and use it for further things, not for when you want a side effect. TOOWTDI. And of course, if saving a line was the reason: shallow = [] for i in deep: shallow.extend(i) -- http://mail.python.org/mailman/listinfo/python-list
Re: Permission Denied
AlbaClause schrieb: > Lawrence D'Oliveiro wrote: > > >>In message <[EMAIL PROTECTED]>, AlbaClause wrote: >> >> >>>Then, to execute the file from from the shell prompt, I had to create a >>>'bin' directory in my home folder, cuz I didn't want to litter >>>my /usr/local/bin folder with useless Python scripts. >> >>Executable files can be kept anywhere, you don't need a special directory >>for them. > > > Yes, I know, but if you want to just enter the filename at the shell prompt, > the file has to be somewhere that it can be found. Otherwise you get the > dreaded "command not found" error. Unless I'm doing something wrong? > > In the most cases, PATH is preconfigured to include "." (. is the current directory as .. is the parent one). You can use ./yourpythonscript in this case. Another possibility is using `python script.py` to let the python interpreter do the work directly. The most "advanced" way would be expanding PATH with /home/youraccount/python/learning (use PATH=$PATH:/path/here..). Choose the one you're most comfortable with. :-) Sincerely, Stargaming -- -- http://mail.python.org/mailman/listinfo/python-list
Create a Multilanguage PDF in Python
Hi guys, I'm disprate with the Pdf Unicode. I try to create a class using ufpdf but some chars are not correct and now I would like try Python because a friend tolds me that it's very powerful. I need a simple script in Python that grab all Records from a MySql table and print in the pdf file. The languages stored in my db are about 25 and they are: Greek English French Hungarian Italian Lithuanian Dutch Portuguese Albanian Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese Polish Romanian Russian Slovene Slovak Swedish Anyone can help me, please? Thanks Perseo -- http://mail.python.org/mailman/listinfo/python-list
convert a long string in binary
i've got a very long string and i wanted to convert it in binary like string = """Monty Python, or The Pythons, is the collective name of the creators of Monty Python's Flying Circus, a British television comedy sketch show that first aired on the BBC on October 5, 1969. A total of 45 episodes were made over four series. However, the Python phenomenon was much greater, spawning stage tours, a musical, four films, numerous albums, and several books, as well as launching the members to individual stardom. The television series, broadcast by the BBC from 1969 to 1974, was conceived, written and performed by Graham Chapman, John Cleese (1969-1973), Terry Gilliam, Eric Idle, Terry Jones and Michael Palin. Loosely structured as a sketch show, but with a highly innovative stream-of-consciousness approach (aided by Terry Gilliam's animations), it pushed the boundaries of what was then considered acceptable, both in terms of style and content. """ string = binary(string) print string // 01010101010101 i 'am searching for something like the binary function (taht doesn't exist) to convert my string directly in binary. Regards Bussiere -- http://mail.python.org/mailman/listinfo/python-list
Text parsing
Hello everybody. Inspired by an example from the book Beginning Python: From Novice to Professional, I started working on a simple text parser which I can hopefully then extend into a more comprehensive system. I've got a little problem, though. My code: test.py import sys def preparse(file): block = [] for line in file: if line.strip(): block.append(line) elif block: yield ''.join(block).strip() block = [] yield '\n' def makeList(file): testOutput = list(preparse(file)) print testOutput testInput = open("test", "r") makeList(testInput) test test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 When I run test.py, it prints this: michiel-sikmas-computer:~/Desktop msikma$ python test.py ['test1\ntest2', 'test3\ntest4\ntest5\ntest6', 'test7\ntest8', 'test9', '\n'] What happened to "test10"? It seems to be gone unless I add two linebreaks at the end of the file. Greets, Michiel Sikma [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: convert a long string in binary
bussiere maillist: > i've got a very long string > and i wanted to convert it in binary Not much tested: _nibbles = {"0":"", "1":"0001", "2":"0010", "3":"0011", "4":"0100", "5":"0101", "6":"0110", "7":"0111", "8":"1000", "9":"1001", "A":"1010", "B":"1011", "C":"1100", "D":"1101", "E":"1110", "F":""} def toBase2(number): if number < 16: return "" + _nibbles["%X" % number] else: d1, d2 = "%X" % number return _nibbles[d1] + _nibbles[d2] convbin = dict((chr(i), toBase2(i)) for i in xrange(256)) def binary(s): return "".join(convbin[c] for c in s) print binary("testing string") Surely there are ways to make it shorter (But it's fast enough). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the ascii code of Chinese characters?
On 2006-08-20 05:56:05, Fredrik Lundh wrote: >>> No. ASCII characters range is 0..127 while Unicode characters range is >>> at least 0..65535. >> >> Actually, Unicode goes beyond 65535. > > you may want to look up "at least" in a dictionary. As a homework, try to parse "at least until" and "goes beyond" and compare the two (a dictionary is not necessarily of help with this :) "range is least 0..65535" : upper_bound >= 65535 "goes beyond 65535" : upper_bound > 65535 For some discussions (like how to represent code points etc) this distinction is crucial. Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
On 2006-08-20 07:18:44, Rhamphoryncus wrote: >> shallow = [] >> [shallow.extend(i) for i in deep] > > I'm sure this has been mentioned before, but listcomps are for when you > want to store the list and use it for further things, not for when you > want a side effect. TOOWTDI. Can you please explain what you mean with this, and maybe why? Thanks, Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter btn visual state with tkMessageBox
Hendrik van Rooyen wrote: > <[EMAIL PROTECTED]> Wrote: > | > | Hendrik van Rooyen wrote: > | > <[EMAIL PROTECTED]> wrote: > | > > | > To: > | > > | > > | > | why is the button sunken when called through a bind method, and not > | > | with the command attribute? > | > | Thank you! > | > | > | > | > | > | ## Cut'nPaste example > | > | from Tkinter import * ... > | > and the "Button" leaves it sunken - because when you release, the > control is > | > no longer there > | > > | > - Hendrik > | Thanks Hendrik - is the command attribute connected to the bindable > | events? > | jm > > I don't have a clue - you are either asking about advanced magic here, > or I don't understand your question - I believe the lower level routines > are common, but I don't *Know* this - so its a pity that some people > who shall be nameless have beaten their brains out in a thread about > a directory name here.. > > You may have noticed that there is another subtle bug with what I have > suggested to you - when you press the offending button, then move the > mouse to move the cursor off the screen button, - the button > "springs back" as expected - but then when you release the mouse > button, off the screen button, the call back is done anyway, instead of > being cancelled when the cursor moves off the screen button. > > - for the command case, the sequence is different, and the call back is done > only if the release is done on the screen button... > > - But this may just be my setup - does yours do the same? > > I don't know how to fix that - you could look at sequences of events - button > push followed by release - But I doubt whether this will help, as its doing > something like that anyway (haven't tried it) > > - Hendrik Same behavior here - Also, I added a bind to Button event and another to ButtonRelease, and also had the command attribute. All three *events* are processed, in similar fashion that you describe above. Finally, the command attribute seems to works like a ButtonRelease BUT still permits a binding to another function on a ButtonRelease event (and only one) so if the lower level functions might be the same the path to them seem different. I found this article that pertains to the question: http://www.ferg.org/thinking_in_tkinter/tt075.py but I'll postpone my own investigation at this time to return to my program ;-) Thanks again, Jean-Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: Text parsing
In <[EMAIL PROTECTED]>, Michiel Sikma wrote: > My code: > > test.py > import sys > > def preparse(file): > block = [] > for line in file: > if line.strip(): > block.append(line) > elif block: > yield ''.join(block).strip() > block = [] + yield ''.join(block).strip() Because your line "test10\n" is still in `block` at this point. > yield '\n' > > […] > > test > test1 > test2 > > test3 > test4 > test5 > test6 > > test7 > test8 > > test9 > > test10 > > > When I run test.py, it prints this: > michiel-sikmas-computer:~/Desktop msikma$ python test.py > ['test1\ntest2', 'test3\ntest4\ntest5\ntest6', 'test7\ntest8', > 'test9', '\n'] > > What happened to "test10"? It seems to be gone unless I add two > linebreaks at the end of the file. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
In <[EMAIL PROTECTED]>, Gerhard Fiedler wrote: > On 2006-08-20 07:18:44, Rhamphoryncus wrote: > >>> shallow = [] >>> [shallow.extend(i) for i in deep] >> >> I'm sure this has been mentioned before, but listcomps are for when you >> want to store the list and use it for further things, not for when you >> want a side effect. TOOWTDI. > > Can you please explain what you mean with this, and maybe why? You should not abuse list comps just to have a one liner. Only use them if you really want to build a list and not just for side effects. The above one-liner builds a list of `None`\s of length ``len(deep)`` for no reason just to throw them away. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the ascii code of Chinese characters?
Gerhard Fiedler wrote: >>> Actually, Unicode goes beyond 65535. >> >> you may want to look up "at least" in a dictionary. > > As a homework, try to parse "at least until" and "goes beyond" and compare > the two (a dictionary is not necessarily of help with this :) > > "range is least 0..65535" : upper_bound >= 65535 > "goes beyond 65535" : upper_bound > 65535 > > For some discussions (like how to represent code points etc) this > distinction is crucial. do you know anything about how Unicode is used in real life, or are you just squabbling ? -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL problem: IOError: cannot identify image file
[EMAIL PROTECTED] wrote: > Doh! Apparently Image.open() wants a path, not a file. So > > i = Image.open('c:\\image2.png') > > works fine. it works fine on files too, if you open them in *binary* mode. -- http://mail.python.org/mailman/listinfo/python-list
Re: Permission Denied
Stargaming <[EMAIL PROTECTED]> writes: > In the most cases, PATH is preconfigured to include "." (. is the current > directory as .. is the parent one). You can use ./yourpythonscript in this > case. I most cases on Unix boxes it isn't configured to include ".". This is so for safety reasons (somebody might replace some command with a tampered binary or a script and capture information that they shouldn't have access to...). The solution of creating a directory and adding it to PATH is the best one, IMHO. Having a "~/bin" is also common for Linux and some distributions of it already ship with it in /etc/skel and in the PATH, so just put a link there or copy your scripts there. > The most "advanced" way would be expanding PATH with > /home/youraccount/python/learning (use PATH=$PATH:/path/here..). Yes. This is the best. > Choose the one you're most comfortable with. :-) ;-) And think about security as well. -- Jorge Godoy <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: write eof without closing
cage wrote: > I want to use a program that has a 'pipe' mode, in which you can use > stdin to send commands to the program. I found out that, when in pipe > mode and you are using the keyboard as input source you can do Ctrl-D to > 'signal' the program that you have finished typing your command. The > program parses and then performs the command, and it doesn't quit. It > quits after 'Quit\n' + Ctrl-D have you tried *flushing* the output stream after each command? -- http://mail.python.org/mailman/listinfo/python-list
Need advice on how to improve this function
I wrote a function that converts a tuple of tuples into html. For example: In [9]: x Out[9]: ('html', ('head', ('title', 'this is the title!')), ('body', ('h1', 'this is the header!'), ('p', 'paragraph one is boring.'), ('p', 'but paragraph 2 ', ('a', {'href': 'http://example.com'}, 'has a link'), '!'))) In [10]: as_html(x, sys.stdout) this is the title! this is the header! paragraph one is boring. but paragraph 2 http://example.com";>has a link! I'd like to know ways to make it better (more efficient, able to deal with enormous-size arguments, etc). How would I write this as a generator? Here's the definition for as_html: def as_html(l, s): "Convert a list or tuple into html and write it to stream s." if isinstance(l, (tuple, list)): tagname = l[0] if isinstance(l[1], dict): attributes = ' '.join(['%s="%s"' % (k, l[1][k]) for k in l[1]]) s.write('<%s %s>' % (tagname, attributes)) else: s.write('<%s>' % tagname) if tagname in ('html', 'head', 'body'): s.write('\n\n') for ll in l[1:]: as_html(ll, s) s.write('' % tagname) if tagname not in ('a', 'b', 'ul'): s.write('\n\n') elif isinstance(l, str): s.write(l) All comments welcome. TIA -- A better way of running series of SAS programs: http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles -- http://mail.python.org/mailman/listinfo/python-list
time.localtime() Format Question
Hello Everyone, I am a brand new Python programmer with barely a month of experience under my belt. Here are my specs: Mac OSX Panther 10.3.9 Jython 2.1 implementation with Hermes BBS python module installed And now the problem... Right now I am having a small problem figuring out how to properly format the "User Last Log-On" date for the new external/door that I am writing for our Hermes BBS. Initially, I was using the following in my user initialization function near the top of the code: user.data.usrUndrLast = time.localtime() "user.data.usrUndrLast" is a user data object that I created to display the last time that a person used the external. As you can see, I an setting the value of the object to "time.localtime()". The problem is that the above code gave me a long string like this: (2006, 8, 19, 23, 39, 15, 5, 231, 0) Well, that obviously was not what I wanted or needed. I don't need seconds, or whatever that is that follows after seconds...And that isn't the format I wanted either. So I scrounged around in the example code for another external I have here, as well as in the hermes.py, (module which contains some of the BBS's proprietary functions), the jython-2.1 folder, (Python implementation I am using with the BBS), and even in my OSX Python installation, and then also on the web, looking for a clue regarding how to get it to do what I want it to do. I figured out that adding [:3] like this: user.data.usrUndrLast = time.localtime()[:3] ...would reduce it to just "(2006, 8, 19)", but that is still not what I want it to do. The format is wrong. I found a lot of interesting stuff inside of "rfc822.py" concerning date and time formats, but I am still not grasping quite how to do this. Right now, I am getting a TypeError, I guess because time.localtime only deals with integers, and I am trying to throw strings at it as well, like this: user.data.usrUndrLast = time.localtime('%a, %d %b %Y') I was hoping that the above code would produce something like this: Sun 20 Aug 2006 ...but what I am getting is a TypeError which states: "TypeError: localtime(): 1st arg can't be coerced to double" So at this point, I am pretty stumped. In the list of players, I just want it to show when they were last logged into the external, preferably in one of the following formats: Sun 20 Aug 2006 Sun Aug 20 2006 Aug 20 2006 08-20-06 08-20-2006 08/20/2006 08/20/06 Once the above code, (user.data.usrUndrLast = time.localtime), initializes their last log-on date, I am using the results in a user list by appending the data to the user list like this: for u in external.users.values(): usrList.append({ 'name': u.data.usrUndrName, 'levl': u.data.usrUndrLevl, 'scor': u.data.usrUndrScor, 'last': u.data.usrUndrLast, # The one we're dealing with }) The above list code queries the external for the values that it has stored for each user. When it gets to the "last" item in the list, the external is supposed to send it the value for "u.data.usrUndrLast", (which it does), which is filled in with the value of "time.localtime()" Once the list is made, the "last" code will be displayed in the user list using this piece of code: print Style(fgLtGreen)('%(last)-10s' % markUsr) For the record, I do have "import time" at the top of my code. I looked all over the place for a module called "time.py", but couldn't find one. So I didn't quite understand where "time.py" was being imported from. I finally figured that it must just be a function which is being imported from one of the jython modules that I was looking at...although I never found an exact function called "time()" or "time.localtime(). So if anyone can lend me a hand with this, I'd really appreciate it. I am really working hard, and doing the best I can to learn Python, (my very first programming language), but I still require some guidance. If anyone here can tell me how to get the results that I want, I would really appreciate if you would write to me directly at: [EMAIL PROTECTED] Thanks so much. -- http://mail.python.org/mailman/listinfo/python-list
Re: Create a Multilanguage PDF in Python
"Perseo" <[EMAIL PROTECTED]> writes: > Hi guys, > > I'm disprate with the Pdf Unicode. I try to create a class using ufpdf > but some chars are not correct and now I would like try Python because > a friend tolds me that it's very powerful. > I need a simple script in Python that grab all Records from a MySql > table and print in the pdf file. > > The languages stored in my db are about 25 and they are: > Greek English French Hungarian Italian Lithuanian Dutch Portuguese > Albanian > Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese > Polish Romanian > Russian Slovene Slovak Swedish You can give reportlab [1] a try. It has support for TrueType fonts and unicode translation using UTF-8. I used to use it for pdf files with polish chars. Some example code: from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont from reportlab.pdfgen import canvas pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf')) c = canvas.Canvas("pl.pdf") c.setFont("Verdana", 12) c.drawString(100, 600, "Witaj, świecie!".decode("iso-8859-2").encode("utf-8")) c.showPage() c.save() [1] http://www.reportlab.org/ -- HTH, Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: PyThreadState_Swap(NULL)
let me try to ask the question again in a simpler more generic way. i thought that the following lines of code, could not fail even if another library in the same process initialized the python interpreter first. if (!Py_IsInitialized()) { Py_Initialize(); } PyEval_InitThreads(); interpreter = PyThreadState_Swap(NULL); what could another library do to make this fail? and is there anything i can do to make this work in all situations? thanks, bryan -- http://mail.python.org/mailman/listinfo/python-list
Help in using introspection to simplify repetitive code
Hello. I'm writing a proxy class, i.e: a class whose methods mostly delegate their functionality to other class object. Most of the methods (which are quite a lot) defined in the class would end up being: def thisIsTheMethodName(self): self._handlerClass.thisIsTheMethodName() The handler object is the same in all methods. I was wondering if there is a way to simplify this proxy class, maybe using some pythonic technique like metaclasses, introspection... any suggestion is appreciated. Thanks, Javier Sanz -- http://mail.python.org/mailman/listinfo/python-list
Re: Help in using introspection to simplify repetitive code
[EMAIL PROTECTED] wrote: > Hello. > I'm writing a proxy class, i.e: a class whose methods mostly delegate > their functionality to other class object. Most of the methods (which > are quite a lot) defined in the class would end up being: > > def thisIsTheMethodName(self): > self._handlerClass.thisIsTheMethodName() > > The handler object is the same in all methods. > > I was wondering if there is a way to simplify this proxy class, maybe > using some pythonic technique like metaclasses, introspection... any > suggestion is appreciated. > > Thanks, > > Javier Sanz http://docs.python.org/ref/attribute-access.html#l2h-206 -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2, proxies and https
Astan Chee <[EMAIL PROTECTED]> writes: > Hi again, > According to > https://demo.launchpad.net/products/python/+bug/56872 > or more specifically, the example of its working code: > http://librarian.demo.launchpad.net/3507227/urllib2_proxy_auth.py > I can use urllib2 via proxy to access a https site(specifically > hooking it up to libgmail). [...] The code at that URL seems to be claiming you CAN'T do that, even with HTTP URLs (note HTTP, not HTTPS). Hopefully (s)he is complaining about 2.4 -- there are a bunch of bugs with this kind of thing fixed in Python 2.5. Re HTTPS: urllib2 does not support the CONNECT method (nor urllib, I think), so no, you can't visit HTTPS URLS through a proxy with vanilla urllib2. There are some hacks lying around in the cookbook and on the Python SF tracker showing how to do it, though. John -- http://mail.python.org/mailman/listinfo/python-list
Re: convert a long string in binary
bussiere maillist wrote: > i've got a very long string > and i wanted to convert it in binary > like > > string = """Monty Python, or The Pythons, is the collective name of > the creators of Monty Python's Flying Circus, a British television > comedy sketch show that first aired on the BBC on October 5, 1969. A > total of 45 episodes were made over four series. However, the Python > phenomenon was much greater, spawning stage tours, a musical, four > films, numerous albums, and several books, as well as launching the > members to individual stardom. > > The television series, broadcast by the BBC from 1969 to 1974, was > conceived, written and performed by Graham Chapman, John Cleese > (1969-1973), Terry Gilliam, Eric Idle, Terry Jones and Michael Palin. > Loosely structured as a sketch show, but with a highly innovative > stream-of-consciousness approach (aided by Terry Gilliam's > animations), it pushed the boundaries of what was then considered > acceptable, both in terms of style and content. > """ > > string = binary(string) > print string > // 01010101010101 > > > i 'am searching for something like the binary function (taht doesn't > exist) to convert my string directly in binary. The gmpy module can convert numbers to binary strings: import gmpy s = """ Yes, well, of course that's just the sort of blinkered philistine pig ignorance I've come to expect from you non-creative garbage. """ ss = '' for c in s: sb = gmpy.digits(ord(c),2) #convert to binary string sb = '0'*(8-len(sb)) + sb #add leading 0's ss += sb print ss 10100101100101100101011100110010111001110111011001010110110001101110111001100110011000100110001101100111010101110010011100110110010100100111010001101111011101100111011100110010011010100111010101110011011101100111010001101110010100100111001101100111001001110110011001100110101001100010011011000110100101101110011010110110010101110010011001010110011001110110111010010110110001101001011100110111010001101001011011100110010100100111011010010110011100100110100101100111011011100110011100100111011011100110001101100101001001001001001001110111011001100101001001100011011001101101011001011010011101000110001001100101011101100101011000110111011001100110011100100110011011010010000101100111010100100110111001100110111000101101011000110111001001100101011101110100011010010111011001100101001001100! 1110111011100100110001001110110011101100101001011101010 > Regards > Bussiere -- http://mail.python.org/mailman/listinfo/python-list
import
i have written script save as hello.py. i can run it. but why cant i import it as a modular in other programs? -- http://mail.python.org/mailman/listinfo/python-list
Re: import
How are you trying to import it? Is it in the same directory as your other script? If not is your python path set correctly? When importing a module that you have written you exlude the .py extension. You should be using: import hello Hope that helps, Will -- http://mail.python.org/mailman/listinfo/python-list
Re: import
bugnthecode 写道: > How are you trying to import it? Is it in the same directory as your > other script? If not is your python path set correctly? > > When importing a module that you have written you exlude the .py > extension. You should be using: > import hello > > Hope that helps, > Will i am on a windows platform. i have written scrip named 123.py. it can be run. ok i save it to C:\Python24 ,exactly the same dir where python works. but " import 123" doesnt work. -- http://mail.python.org/mailman/listinfo/python-list
Re: import
Try putting it in C:\Python24\Lib\site-packages instead. [EMAIL PROTECTED] wrote: >bugnthecode åéï¼ > >> How are you trying to import it? Is it in the same directory as your >> other script? If not is your python path set correctly? >> >> When importing a module that you have written you exlude the .py >> extension. You should be using: >> import hello >> >> Hope that helps, >> Will > >i am on a windows platform. i have written scrip named 123.py. it can >be run. ok i save it to C:\Python24 ,exactly the same dir where python >works. but " import 123" doesnt work. -- http://mail.python.org/mailman/listinfo/python-list
Re: import
resnak wrote: > Try putting it in C:\Python24\Lib\site-packages instead. i have done that , dest not work as well. -- http://mail.python.org/mailman/listinfo/python-list
Re: import
[EMAIL PROTECTED] wrote: > bugnthecode 写道: > >> How are you trying to import it? Is it in the same directory as your >> other script? If not is your python path set correctly? >> >> When importing a module that you have written you exlude the .py >> extension. You should be using: >> import hello >> >> Hope that helps, >> Will > > i am on a windows platform. i have written scrip named 123.py. it can > be run. ok i save it to C:\Python24 ,exactly the same dir where python > works. but " import 123" doesnt work. You can't import modules whose names have non-identifier names with plain "import". Or would you like "123" to refer to a module? If you have to do this (and I have a strong feeling that you haven't) use the built-in function __import__(). Georg -- http://mail.python.org/mailman/listinfo/python-list
Send to all clients using UDP in Twisted
Hi Everyone, I am trying to right a server that can receive a message and send it to all clients using UDP on twisted. I have got it so far that it can echo to the client that sent the message but not to the rest. I tried using multicast but that requires almost total rewrite, and the client which is not in python can't handle it. Are there any alternative methods or a workaround? Thanks alot for your time! -- http://mail.python.org/mailman/listinfo/python-list
Re: import
If your still having trouble how are you running python? If you run cmd and THEN type python it is not operating in the python24 directory and runs in the directory cmd was in before the command. Otherwise make sure you don't have any previous python installs. -- http://mail.python.org/mailman/listinfo/python-list
Re: time.localtime() Format Question
OleMacGeezer wrote: > Hello Everyone, > Hola > (2006, 8, 19, 23, 39, 15, 5, 231, 0) > > Well, that obviously was not what I wanted or needed. I don't > need seconds, or whatever that is that follows after > seconds...And that isn't the format I wanted either. I'm sorry I didn't have time to grep your entire post, but maybe this will help: >>> import time >>> t = time.localtime() >>> t (2006, 8, 20, 12, 48, 52, 6, 232, 1) >>> time.strftime('%a, %d %b %Y', t) 'Sun, 20 Aug 2006' -greg -- http://mail.python.org/mailman/listinfo/python-list
Re: import
Georg Brandl wrote: > [EMAIL PROTECTED] wrote: > > bugnthecode 写道: > > > >> How are you trying to import it? Is it in the same directory as your > >> other script? If not is your python path set correctly? > >> > >> When importing a module that you have written you exlude the .py > >> extension. You should be using: > >> import hello > >> > >> Hope that helps, > >> Will > > > > i am on a windows platform. i have written scrip named 123.py. it can > > be run. ok i save it to C:\Python24 ,exactly the same dir where python > > works. but " import 123" doesnt work. > > You can't import modules whose names have non-identifier names with > plain "import". Or would you like "123" to refer to a module? > > If you have to do this (and I have a strong feeling that you haven't) > use the built-in function __import__(). > you have to name your program with the name mymodule,or something like that when you use "import". does python have a clear declaration on how to name a module? -- http://mail.python.org/mailman/listinfo/python-list
Re: import
01 wrote: > Georg Brandl wrote: >> [EMAIL PROTECTED] wrote: >> > bugnthecode 写道: >> > >> >> How are you trying to import it? Is it in the same directory as your >> >> other script? If not is your python path set correctly? >> >> >> >> When importing a module that you have written you exlude the .py >> >> extension. You should be using: >> >> import hello >> >> >> >> Hope that helps, >> >> Will >> > >> > i am on a windows platform. i have written scrip named 123.py. it can >> > be run. ok i save it to C:\Python24 ,exactly the same dir where python >> > works. but " import 123" doesnt work. >> >> You can't import modules whose names have non-identifier names with >> plain "import". Or would you like "123" to refer to a module? >> >> If you have to do this (and I have a strong feeling that you haven't) >> use the built-in function __import__(). >> > you have to name your program with the name mymodule,or something like > that when you use "import". does python have a clear declaration on > how to name a module? A module name can be everything also usable as a Python identifier. This means that it contains only letters, digits and underscores and doesn't start with a digit. Running a file as the main file, using "python 123.py" works because Python then won't need to provide the file name as a name in the script. Georg -- http://mail.python.org/mailman/listinfo/python-list
Input from the same file as the script
Can the input to the python script be given from the same file as the script itself. e.g., when we execute a python script with the command 'python http://mail.python.org/mailman/listinfo/python-list
Re: Input from the same file as the script
[EMAIL PROTECTED] wrote: > Can the input to the python script be given from the same file as the > script itself. e.g., when we execute a python script with the command > 'python > When I ran the below the python interpreter gave an error. *sigh* Why do you think that we could guess what error this may be? In this case, it is likely a SyntaxError because you used input() instead of raw_input(). > e.g., > scriptName: > --- > x = input("The value of x is taken from the source code file itself as > input is redirected to it") > > print x > > "Value intended for the variable x" > Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem installing Python 2.4.3 on FreeBSD 5.3-RELEASE-p31
[EMAIL PROTECTED] schrieb: > I assume this is related to the configure warning... ? Same error with > just a standard "./configure" and "make". > > Any help would be great :) If you don't need the curses module, go on with the installation. It's a known bug in FreeBSD's curses header file. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: import
Georg Brandl wrote: > 01 wrote: > > Georg Brandl wrote: > >> [EMAIL PROTECTED] wrote: > >> > bugnthecode 写道: > >> > > >> >> How are you trying to import it? Is it in the same directory as your > >> >> other script? If not is your python path set correctly? > >> >> > >> >> When importing a module that you have written you exlude the .py > >> >> extension. You should be using: > >> >> import hello > >> >> > >> >> Hope that helps, > >> >> Will > >> > > >> > i am on a windows platform. i have written scrip named 123.py. it can > >> > be run. ok i save it to C:\Python24 ,exactly the same dir where python > >> > works. but " import 123" doesnt work. > >> > >> You can't import modules whose names have non-identifier names with > >> plain "import". Or would you like "123" to refer to a module? > >> > >> If you have to do this (and I have a strong feeling that you haven't) > >> use the built-in function __import__(). > >> > > you have to name your program with the name mymodule,or something like > > that when you use "import". does python have a clear declaration on > > how to name a module? > > A module name can be everything also usable as a Python identifier. This > means that it contains only letters, digits and underscores and doesn't > start with a digit. > > Running a file as the main file, using "python 123.py" works because > Python then won't need to provide the file name as a name in the script. On an almost totally unrelated note...(except that it definitely belongs in a thread entitled "import")... I've occasionally run into difficulty when I fail to include a she-bang in my script. If the first word of the script is import, which it often is for quickly written scripts that contain an import line before any doc string and that doesn't have "#!/usr/bin/env python", bash doesn't report a syntax error. Instead, it annoyingly runs the ImageMagick command import, which dutifully sits there waiting for a mouse click. The first time this happened, it took me a good 15 minutes to figure out what was happening. (The first instance was more subtle than forgetting the she-bang, as I'd merely forgotten the "bang" and the "#/usr/bin/env python" looked pretty good when I looked at the file.) I'm just curious if anyone else has ever bumped into that mistake. -- http://mail.python.org/mailman/listinfo/python-list
Access to sys.argv when python interpreter is invoked in some modes like 'python -c "command"'
The python tutorial says "When the script name is given as '-' (meaning standard input), sys.argv[0] is set to '-'. When -c command is used, sys.argv[0] is set to '-c'. " but when we use a command say 'python -c "command"' where can we access "sys.argv" (are there some commands where "sys.argv" is accessed. I can run 'python -c "import sys sys.argv", I get an error message -Tiro -- http://mail.python.org/mailman/listinfo/python-list
Re: Access to sys.argv when python interpreter is invoked in some modes like 'python -c "command"'
[EMAIL PROTECTED] wrote: > The python tutorial says > "When the script name is given as '-' (meaning standard input), > sys.argv[0] is set to '-'. When -c command is used, sys.argv[0] is > set to '-c'. " but when we use a command say 'python -c "command"' > where can we access "sys.argv" (are there some commands where > "sys.argv" is accessed. I can run 'python -c "import sys sys.argv", I > get an error message > > -Tiro When you get an error message, and you ask a question concerning the error message, *post* the error message. But first, read it yourself. It will probably tell you what's wrong. That's why it exists. Meantime, what's your question? BTW, "import sys sys.argv" is invalid python. When putting code statements together on one line like this you must separate them with ";". I.e. "import sys; sys.argv". Note that this will still not do what (I'm guessing) you want because this code is not being executed interactively. It will simply "get" the value of sys.argv and then throw it away. Try "import sys; print sys.argv", if you want to print the value of sys.argv. Happy coding, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
[ANN] PyYAML-3.04: YAML parser and emitter for Python
Announcing PyYAML-3.04 A new release of PyYAML, featuring LibYAML bindings and support for recursive structures, is now available: http://pyyaml.org/wiki/PyYAML Changes === * Include experimental LibYAML bindings. * Fully support recursive structures. * Fix a number of bugs and annoyances (see http://pyyaml.org/wiki/PyYAML#History for more details). Resources = PyYAML homepage: http://pyyaml.org/wiki/PyYAML PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-3.04.tar.gz ZIP package: http://pyyaml.org/download/pyyaml/PyYAML-3.04.zip Windows installer: http://pyyaml.org/download/pyyaml/PyYAML-3.04.win32-py2.3.exe http://pyyaml.org/download/pyyaml/PyYAML-3.04.win32-py2.4.exe PyYAML SVN repository: http://svn.pyyaml.org/pyyaml Submit a bug report: http://pyyaml.org/newticket?component=pyyaml YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistance. Example === >>> import yaml >>> print yaml.load(""" ... &A { ... direct self reference: *A, ... indirect self references: [*A, *A, *A] ... } ... """) {'direct self reference': {...}, 'indirect self references': [{...}, {...}, {...}]} Copyright = The PyYAML module is written by Kirill Simonov <[EMAIL PROTECTED]>. PyYAML is released under the MIT license. This release is developed with the support of the Google Summer of Code program under the mentorship of Clark Evans. -- http://mail.python.org/mailman/listinfo/python-list
radio buttons in curses
Hi, I want to add some radio and check buttons to my curses script. As I understand it, there are no buttons in the 'basic' curses module. Now, I found the curses-extra module, but I not able to download and install it. Does anybody have an idea, where I can download the module or, even better, how I can create radio and check buttons with the 'ordinary' curses module? Would be nice... Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: sum and strings
Rhamphoryncus <[EMAIL PROTECTED]> wrote: ... > > > I believe the prefered method to flatten a list of lists is this: > > > > > > shallow = [] > > > for i in deep: > > > shallow.extend(i) > > > > > > Yes, it's three lines. It's also very easy to read. reduce() and > > > sum() are not. > > > > I'd like to squeeze in the listcomp version, not because it is one line > > shorter, but because I, and maybe others prefer short listcomps such as > > the folowing: > > > > shallow = [] > > [shallow.extend(i) for i in deep] > > I'm sure this has been mentioned before, but listcomps are for when you > want to store the list and use it for further things, not for when you > want a side effect. TOOWTDI. > > And of course, if saving a line was the reason: > > shallow = [] > for i in deep: shallow.extend(i) Another alternative equivalent to shallow = sum(deep, []) but based on the "proper" usage of list comprehensions is shallow = [ item for sublist in deep for item in sublist ] In terms of performance, however, the simple loop that you (rhamph) posted is generally best -- e.g., with Python 2.5c1 on a MacbookPro: brain:~/downloads alex$ python -mtimeit -s'deep=[range(9)]*9' 's=sum(deep,[])' 10 loops, best of 3: 11.2 usec per loop brain:~/downloads alex$ python -mtimeit -s'deep=[range(9)]*9' 's=[] > for sublist in deep: s.extend(sublist)' 10 loops, best of 3: 6.92 usec per loop brain:~/downloads alex$ python -mtimeit -s'deep=[range(9)]*9' 's=[] [s.extend(sublist) for sublist in deep]' 10 loops, best of 3: 8.48 usec per loop brain:~/downloads alex$ python -mtimeit -s'deep=[range(9)]*9' 's=[item for sublist in deep for item in sublist]' 10 loops, best of 3: 17.1 usec per loop Alex -- http://mail.python.org/mailman/listinfo/python-list
What do you want in a new web framework?
Hello Everyone, Now, I'm working on a new web framework. I tried many test on the other programming languages. Then i decided to use python on my web framework project. Now i want to listen all of you. What do you want in that web framework(Easy use of Database, Easy use of XML, GUI Designer, etc...)? I'm wating your answers. Thank you for all answers...! King Regards, Emrah Ayanoglu -- http://mail.python.org/mailman/listinfo/python-list
What do you want in a new web framework?
Hello Everyone, Now, I'm working on a new web framework. I tried many test on the other programming languages. Then i decided to use python on my web framework project. Now i want to listen all of you. What do you want in that web framework(Easy use of Database, Easy use of XML, GUI Designer, etc...)? I'm wating your answers. Thank you for all answers...! King Regards, Emrah Ayanoglu -- http://mail.python.org/mailman/listinfo/python-list
newbie question about import tools
i have just downloas python and trying to import tools module C:\Documents and Settings\toto>python Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v Type "help", "copyright", "credits" or "license" >>> import tools Traceback (most recent call last): File "", line 1, in ? ImportError: No module named tools >>> import os >>> print os >>> import code >>> print code >>> do i need to download tools.pyc ? -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question about import tools
On Sunday 20 August 2006 21:39, [EMAIL PROTECTED] wrote: > i have just downloas python and trying to import tools module > > C:\Documents and Settings\toto>python > Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v > Type "help", "copyright", "credits" or "license" > > >>> import tools > > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named tools > > >>> import os > >>> print os > > > > >>> import code > >>> print code > > > > > do i need to download tools.pyc ? There is no such thing as "tools" in the standard library (http://www.python.org/doc/current/lib/lib.html). Why do you expect something like that? Cheers Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question about import tools
<[EMAIL PROTECTED]> wrote: > do i need to download tools.pyc ? Python doesn't have any "tools" module builtin. So, what tool is? -- Lawrence - http://www.oluyede.org/blog "Nothing is more dangerous than an idea if it's the only one you have" - E. A. Chartier -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you want in a new web framework?
In <[EMAIL PROTECTED]>, emrahayanoglu wrote: > Now, I'm working on a new web framework. I tried many test on the other > programming languages. Then i decided to use python on my web framework > project. > > Now i want to listen all of you. What do you want in that web > framework(Easy use of Database, Easy use of XML, GUI Designer, etc...)? > > I'm wating your answers. Thank you for all answers...! Don't think that yet another Python web framework is really needed. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you want in a new web framework?
[EMAIL PROTECTED] wrote: > Hello Everyone, > > Now, I'm working on a new web framework. I tried many test on the other > programming languages. Then i decided to use python on my web framework > project. > > Now i want to listen all of you. What do you want in that web > framework(Easy use of Database, Easy use of XML, GUI Designer, etc...)? > > I'm wating your answers. Thank you for all answers...! > > King Regards, > > Emrah Ayanoglu Don't want to sound too conservative but really nothing that either - Django - Turbogear - or the "myghty" Pylons (my personal favorite) cannot provide efficiently today! EuGeNe -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you want in a new web framework?
Really, really good documentation.DaveOn 20 Aug 2006 11:58:50 -0700, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote:Hello Everyone,Now, I'm working on a new web framework. I tried many test on the other programming languages. Then i decided to use python on my web frameworkproject.Now i want to listen all of you. What do you want in that webframework(Easy use of Database, Easy use of XML, GUI Designer, etc...)? I'm wating your answers. Thank you for all answers...!King Regards,Emrah Ayanoglu--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
uploading files to file system/zipping/downloading problems
I am currently uploading a file from a users computer to the file system on my server using python, just reading the file and writing the binaries. total_data=' ' while True: data = upload_file.file.read(8192) if not data: break total_data += data f = open(target_file_name, 'wb') f.write(total_data) f.close However when i download the file from the server it is not intact and it cannot be opened. It is happening with every type of file. It seemed to be working before and now it is..maybe I goofed up and deleted something. However I can't seem to find it. any ideas?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Help in using introspection to simplify repetitive code
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello. > I'm writing a proxy class, i.e: a class whose methods mostly delegate > their functionality to other class object. Most of the methods (which > are quite a lot) defined in the class would end up being: > > def thisIsTheMethodName(self): >self._handlerClass.thisIsTheMethodName() Are these parameterless static methods or should this be self._handlerClass.thisIsTheMethodName(self) or does self get auto-bound even though not a _handlerClass instance? (I have never needed or done such delegation.) > The handler object is the same in all methods. > > I was wondering if there is a way to simplify this proxy class, maybe > using some pythonic technique like metaclasses, introspection... any > suggestion is appreciated. My immediate thought would be to start with _forwarded = set(..) # of forwarded method names def __getattr__(self, name): if name in _forwarded: return getattr(self._handlerClass, name) but I am not sure if this gives the right wrapping and binding. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Create a Multilanguage PDF in Python
Hi again, WORKS!!! I download all I need as python + reportlab. Only 2 questions: 1. I need all of this package? because it is 6Mb! 2. How can I connect my software with MySql. In my Hosting is present the Python support but I don't thing that the MySQLdb is present. How can I solve this little problem? Thanks Perseo Rob Wolfe wrote: > "Perseo" <[EMAIL PROTECTED]> writes: > > > Hi guys, > > > > I'm disprate with the Pdf Unicode. I try to create a class using ufpdf > > but some chars are not correct and now I would like try Python because > > a friend tolds me that it's very powerful. > > I need a simple script in Python that grab all Records from a MySql > > table and print in the pdf file. > > > > The languages stored in my db are about 25 and they are: > > Greek English French Hungarian Italian Lithuanian Dutch Portuguese > > Albanian > > Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese > > Polish Romanian > > Russian Slovene Slovak Swedish > > You can give reportlab [1] a try. It has support for TrueType fonts > and unicode translation using UTF-8. I used to use it for pdf files > with polish chars. > > Some example code: > > > from reportlab.pdfbase import pdfmetrics > from reportlab.pdfbase.ttfonts import TTFont > from reportlab.pdfgen import canvas > > pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf')) > c = canvas.Canvas("pl.pdf") > c.setFont("Verdana", 12) > c.drawString(100, 600, "Witaj, ¶wiecie!".decode("iso-8859-2").encode("utf-8")) > c.showPage() > c.save() > > > > [1] http://www.reportlab.org/ > > -- > HTH, > Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: Create a Multilanguage PDF in Python
Hi Rob, thank you for your answer, but I'm a newbie in Web application written in Python. Now I try your suggestion ... Thanks Perseo Rob Wolfe wrote: > "Perseo" <[EMAIL PROTECTED]> writes: > > > Hi guys, > > > > I'm disprate with the Pdf Unicode. I try to create a class using ufpdf > > but some chars are not correct and now I would like try Python because > > a friend tolds me that it's very powerful. > > I need a simple script in Python that grab all Records from a MySql > > table and print in the pdf file. > > > > The languages stored in my db are about 25 and they are: > > Greek English French Hungarian Italian Lithuanian Dutch Portuguese > > Albanian > > Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese > > Polish Romanian > > Russian Slovene Slovak Swedish > > You can give reportlab [1] a try. It has support for TrueType fonts > and unicode translation using UTF-8. I used to use it for pdf files > with polish chars. > > Some example code: > > > from reportlab.pdfbase import pdfmetrics > from reportlab.pdfbase.ttfonts import TTFont > from reportlab.pdfgen import canvas > > pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf')) > c = canvas.Canvas("pl.pdf") > c.setFont("Verdana", 12) > c.drawString(100, 600, "Witaj, ¶wiecie!".decode("iso-8859-2").encode("utf-8")) > c.showPage() > c.save() > > > > [1] http://www.reportlab.org/ > > -- > HTH, > Rob -- http://mail.python.org/mailman/listinfo/python-list
Python Expert
Hi guys, we are looking for a python developer for a European project. This project is multilangual and free it is called EuroCv and it need a module for exporting data in PDF. As web developer I try to create this module but It's too complicate for me. Check out the service www.eurocv.eu for more details. Contact us by Skype chat system our nick is eurocv. Thanks -- http://mail.python.org/mailman/listinfo/python-list
List comparison help please
I am trying to compare a list of items to the list of files generated by os.listdir. I am having trouble getting this to work and think I may be going down the wrong path. Please let me know if hter is a better way to do this. THis is what I have for my class so far: import os, sys class MatchList: def __init__(self, dir, file): self.dir = os.listdir(dir) self.flist = open(file, 'r').readlines() self.matches = [] def matcher(self): #~ matches = [] for fname in self.dir: #~ print fname if fname[-4] == '.': for item in self.flist: if item == fname[:-4]: pass else: self.matches.append(fname) #~ else: #~ break #~ if self.matches == '': #~ print "Sorry, there was no match." #~ else: #~ for item in matches: #~ print item def matchedFiles(self): for item in self.matches: print item if __name__ == '__main__': dir = sys.argv[1] file = sys.argv[2] list = open(file, 'r').readlines() test = MatchList(dir, file) test.matcher() test.matchedFiles() Thanks in advance for your help. :) SA -- http://mail.python.org/mailman/listinfo/python-list
Re: Permission Denied
On Sun, 20 Aug 2006 10:35:31 -0300, Jorge Godoy <[EMAIL PROTECTED]> wrote: > Stargaming <[EMAIL PROTECTED]> writes: > >> In the most cases, PATH is preconfigured to include "." (. is the current >> directory as .. is the parent one). > > I most cases on Unix boxes it isn't configured to include ".". Indeed -- but "Stargaming" might have missed a negation somewhere, because he went on to say [rearranged from the above] >> You can use ./yourpythonscript in this >> case. which is precisely what you /don't/ need to type if you have placed . in your $PATH. > The solution of creating a directory and adding it to PATH is the best one, > IMHO. Having a "~/bin" is also common for Linux and some distributions of it > already ship with it in /etc/skel and in the PATH, so just put a link there or > copy your scripts there. > >> The most "advanced" way would be expanding PATH with >> /home/youraccount/python/learning (use PATH=$PATH:/path/here..). > > Yes. This is the best. I wouldn't want random scripts under development ending up in my $PATH, not even my own. When you're just playing with/developing scripts, it's better to execute them by path (./foo.py etc). When you think they work and you have a long-term use for them, you install them globally, or copy, move or link them into your ~/bin/. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: cloning generator iterators
Bernhard Mulder wrote: > [ attempt to clone/fork a generator ] You can do this, but you can't pickle the results. (If you want pickling, use Stackless - I've not tried pickling generators in stackless because I don't use stackless, but it looks pretty clear you can pickle them there) > Question: What is the best way to implement this clone operation? However you should be able to do what you want using the small extension "statesaver" which you can grab from * http://www.gosubway.org/install/statesaver.c The statesaver allows you to clone generators in the way that you want. FWIW, I can see lots of situations where this would be useful - mainly in the area of dealing with search spaces (After all, this effectively allows you to fork the generator). Michael. -- http://kamaelia.sourceforge.net/Home - Concurrency, Networking, Simplicity -- http://mail.python.org/mailman/listinfo/python-list
Re: uploading files to file system/zipping/downloading problems
On Sun, 20 Aug 2006 13:49:22 -0700, OriginalBrownster wrote: > I am currently uploading a file from a users computer to the file > system on my server using python, just reading the file and writing the > binaries. > > total_data=' ' > while True: > data = upload_file.file.read(8192) > if not data: > break > total_data += data > f = open(target_file_name, 'wb') > f.write(total_data) > f.close > > However when i download the file from the server it is not intact and > it cannot be opened. It is happening with every type of file. > > It seemed to be working before and now it is..maybe I goofed up and > deleted something. > However I can't seem to find it. > > any ideas?? You are re-creating, and overwriting, your file every time you go into that while loop. -- http://mail.python.org/mailman/listinfo/python-list
Re: Text to MP3 using pyTTS - Non-programmer question
Marc Shapiro wrote: > From what I've seen, pyTTS is Windows only. Is there a package that > runs on linux that provides similar functionality. I have festival and > festlite, but I would prefer a Python solution. From: http://www.cam.org/~nico/cicero/cicero-README.txt """ Cicero TTS: A Small, Fast and Free Text-To-Speech Engine. Copyright 2003-2006 Nicolas Pitre <[EMAIL PROTECTED]> Copyright 2003-2006 Stéphane Doyon <[EMAIL PROTECTED]> Version 0.7, March 2006 Our TTS engine currently speaks French and some resemblance of English, although we hope it can some day be taught to speak good English or other languages. The engine uses context-sensitive rules to produce phonemes from the text. It relies on MBROLA (http://tcts.fpms.ac.be/synthesis/mbrola.html) to generate actual audio output from the phonemes. The TTS engine is implemented using the Python programming language. We've come up with this TTS to try and meet our own needs as blind users. """ """ This is still an early release of our TTS, quality is beta-ish. Installation/integration surely has rough edges still, and pronunciation is constantly improving. The TODO-list is still generous. """ I've not tried this, but I suspect this might be a good place to start (though coaxing it to do english might well be a project in itself, depending on what they mean by "some semblance of English" :-) Regards, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the ascii code of Chinese characters?
On 2006-08-20 10:31:20, Fredrik Lundh wrote: >> "range is least 0..65535" : upper_bound >= 65535 >> "goes beyond 65535" : upper_bound > 65535 >> >> For some discussions (like how to represent code points etc) this >> distinction is crucial. > > do you know anything about how Unicode is used in real life, or are you > just squabbling ? Your point is? Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Send to all clients using UDP in Twisted
Elliot Hughes wrote: > Hi Everyone, I am trying to right a server that can receive a message > and send it to all clients using UDP on twisted. I have got it so far > that it can echo to the client that sent the message but not to the > rest. I tried using multicast but that requires almost total rewrite, > and the client which is not in python can't handle it. Are there any > alternative methods or a workaround? > > Thanks alot for your time! > Depends on you network topology and infrastructure, one possible option is that if the clients are on the same subnet you could send it to the broadcast address, however that wouldn't make your netadmin happy, if he didn't filter broadcast in the first place (many switches default filter that). -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: List comparison help please
20 Aug 2006 14:47:14 -0700, Bucco <[EMAIL PROTECTED]>: > I am trying to compare a list of items to the list of files generated > by os.listdir. I am having trouble getting this to work and think I > may be going down the wrong path. Please let me know if hter is a > better way to do this. THis is what I have for my class so far: > Have you tried using sets? >>> import os >>> os.listdir('/') ['lost+found', 'var', 'etc', 'media', 'cdrom', 'bin', 'boot', 'dev', 'home', 'initrd', 'lib', 'mnt', 'opt', 'proc', 'root', 'sbin', 'srv', 'sys', 'tmp', 'usr', 'initrd.img', 'vmlinuz', 'windows', 'initrd.img.old', 'vmlinuz.old'] >>> s = set(os.listdir('/')) >>> p = set(['opt', 'mnt', 'initrd', 'home', 'tmp', 'lib', 'media', 'boot', 'usr', 'var', 'proc', 'bin', 'sys', 'initrd.img.old', 'cdrom', 'lost+found', 'sbin', 'vmlinuz.old', 'windows']) >>> s - p set(['dev', 'etc', 'vmlinuz', 'srv', 'root', 'initrd.img']) -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Tim Golden wrote: > | > [gel] > | > > | > | I have written a python client server app [...] > | > | I want to run the client end of the app more or less invisibly > | > | (no console) on the XP clients when ever a users logs on. > > While this isn't answering the question you first > asked, might I suggest an alternative approach? > Obviously, I'm working from no more than the sketch > you gave of your app and its requirements, but might > it be worth turning the problem on its head, and > using WMI? > > Advantages: > > 1) WMI will -- almost certainly -- already be running on your > target machines. No need to install your own service. > > 2) WMI has a fair range of mechanisms for determining > what processes are starting, stopping, etc. and for > manipulating them remotely. > > 3) You can, at least in theory, access any number of machines > from a central server, and with a bit of judicious threading > or looping, you should be able to generate a fair bit of resilience > to machine dropouts etc. > > Disadvantages: > > 1) What you're doing may be far more complex than you've > outlined, requiring a local service per target machine > for other reasons. > > 2) You may have already invested some amount of time and > effort in developing an app which does what you want. > > 3) I may have entirely misunderstood what you're trying > to do in any case. > > If you're interested and want a code sample, let me know. > If you're not, that's fine. > > TJG > Hi Tim Thanks for your suggestion, I have just got to read the post now and appolagise to you and the others who have replied to my post for the big gap. I will have a read today and get back to you. -- http://mail.python.org/mailman/listinfo/python-list
looking for help with dex tracker
I have a project on sourceforge that is going to be a tracker for csound currently it is a text editor with some external programs attached. There is no complex thing to do to join just post to http://groups.google.com/group/dexrow-software-and-programming-group the software is available at https://sourceforge.net/projects/dex-tracker currently what I am trying to do is write reusable routines for text file conversion i.e. remove a representation of an instrument or add one. -- http://mail.python.org/mailman/listinfo/python-list
Re: List comparison help please
Bucco wrote: > I am trying to compare a list of items to the list of files generated > by os.listdir. I am having trouble getting this to work and think I > may be going down the wrong path. Please let me know if hter is a > better way to do this. THis is what I have for my class so far: > > import os, sys > > class MatchList: > def __init__(self, dir, file): > self.dir = os.listdir(dir) > self.flist = open(file, 'r').readlines() > self.matches = [] > def matcher(self): > #~ matches = [] > for fname in self.dir: > #~ print fname > if fname[-4] == '.': > for item in self.flist: > if item == fname[:-4]: > pass > else: > self.matches.append(fname) > #~ else: > #~ break > #~ if self.matches == '': > #~ print "Sorry, there was no match." > #~ else: > #~ for item in matches: > #~ print item > def matchedFiles(self): > for item in self.matches: print item > > if __name__ == '__main__': > dir = sys.argv[1] > file = sys.argv[2] > list = open(file, 'r').readlines() > test = MatchList(dir, file) > test.matcher() > test.matchedFiles() > > > Thanks in advance for your help. > > :) > SA 0) What kind of trouble? 1) Don't use "dir", "file", and "list" as variable names, those are already python built in objects (the dir() function, list type, and file type, respectively.) 2) 'r' is the default for open(), omit it. "self.flist = open(file).readlines()" 3) The output of file.readlines() includes the newline at the end of each line. Use the rstrip() method of strings if this is a problem for you: lines = [line.rstrip() for line in open(file).readlines()] 4) This is bizarre: > if item == fname[:-4]: > pass > else: > self.matches.append(fname) why not "if item != fname[:-4]: self.matches.append(fname)"? But, note, you're appending fname to self.matches once for every item in self.flist that it does not match. You might want to put a break statement in there: if item != fname[:-4]: self.matches.append(fname) break But see the next point: 5) Since you have a list of things you're matching (excluding actually) this part: > for item in self.flist: > if item == fname[:-4]: > pass > else: > self.matches.append(fname) could become: if fname[:-4] not in self.flist: self.matches.append(fname) 6) Why are you using #~ for comments? Also, check out os.path.splitext() http://docs.python.org/lib/module-os.path.html#l2h-1761 HTH, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: List comparison help please
Simon Forman wrote: > 1) Don't use "dir", "file", and "list" as variable names, those are > already python built in objects (the dir() function, list type, and > file type, respectively.) Thanks. My own stupidity on this one. > 2) 'r' is the default for open(), omit it. "self.flist = > open(file).readlines()" > Could you clarify? Show an example. Sorry if I sound newbyish, but I am. > 5) Since you have a list of things you're matching (excluding actually) > this part: > > > for item in self.flist: > > if item == fname[:-4]: > > pass > > else: > > self.matches.append(fname) > > could become: > > if fname[:-4] not in self.flist: self.matches.append(fname) Thanks. This was what I was looking for. > 6) Why are you using #~ for comments? This is just the automatic commenting on scite. I put my cursor on the line I want to comment and press ctrl-q ans scite comments out the whole line or selection. As for why the lines are commented; I commented these lines so I could test out some of the code prior to running the next bit. > Also, check out os.path.splitext() > http://docs.python.org/lib/module-os.path.html#l2h-1761 > I will check this out also. Thank You for your help. You have answered some questions for me. Thanks:) SA -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Roger Upole wrote: > You can use the Task Scheduler to run a script at login. > It's not as robust as creating a service, but it's much less > work. > > Roger > OK thanks Roger I will have a bit a look at that option. It is fairly important for the solution to be robust, but this maybe enough. Cheers > "gel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Hi > > I have written a python client server app that keeps an eye on > > processes starting and ending on a client and makes decision on what to > > do based on information from the server end. I want to run the client > > end of the app more or less invisibly (no console) on the XP clients > > when ever a users logs on. What would be the best way to get this > > done? A bit more info on the purpose of the app... it is to act as a > > licence server, where we have a limited number of licences for software > > and the software installed on all PCs. The app will only allow a pre > > defined number of clients to run the software at any one time. > > -- http://mail.python.org/mailman/listinfo/python-list
string validation/ form validation
Hi there: I just had a quick thought of something that might be useful to me when creating my web app and I wanted some help on the idea; since this group has been helpful in the past. in my app I have a few html forms that require the user to enter in data, in string form is it possible to validate if the string is in a valid form..such as check if its a list An example ask the user to enter in a list seperated by commas so i want something like "apple,banana,grapes" is there a way to validate that it was entered that way? Any help would be appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: string validation/ form validation
OriginalBrownster wrote: > Hi there: > > I just had a quick thought of something that might be useful to me when > creating my web app and I wanted some help on the idea; since this > group has been helpful in the past. > > in my app I have a few html forms that require the user to enter in > data, in string form > > is it possible to validate if the string is in a valid form..such as > check if its a list > > An example > > ask the user to enter in a list seperated by commas > > so i want something like "apple,banana,grapes" > > is there a way to validate that it was entered that way? > > Any help would be appreciated Yes. Please read this: http://www.catb.org/~esr/faqs/smart-questions.html Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: uploading files to file system/zipping/downloading problems
Assuming your upload_file.file.read() function works, the overwriting should be the only issue. Just want to point out that total_data += data is not advisable for this example (speed/efficiency issue, although i'm sure it could probably be even faster than what I replace it with if u decided to use arrays, but it's probably not worth it XD), and I think open() was replaced by file(), although they're probably interchangable. new code - total_data = ' ' temp_data = [] while True: data = upload_file.file.read(8192) if not data: break temp_data.append(data) total_data = ' '.join(temp_data) somefile = file(target_file_name, 'wb') somefile.write(total_data) f.close() --- OriginalBrownster wrote: > I am currently uploading a file from a users computer to the file > system on my server using python, just reading the file and writing the > binaries. > > total_data=' ' > while True: > data = upload_file.file.read(8192) > if not data: > break > total_data += data > f = open(target_file_name, 'wb') > f.write(total_data) > f.close > > However when i download the file from the server it is not intact and > it cannot be opened. It is happening with every type of file. > > It seemed to be working before and now it is..maybe I goofed up and > deleted something. > However I can't seem to find it. > > any ideas?? -- http://mail.python.org/mailman/listinfo/python-list
Re: write eof without closing
On 2006-08-19, Tim Chase <[EMAIL PROTECTED]> wrote: >>> can i write a eof to a file descriptor without closing it? >> >> No. Not on Windows, OS-X, or Unix. There is no such thing as >> "an eof". >> >> On CP/M Ctrl-Z is used as EOF for text files. > > Common Dos/Window convention also uses ctrl+Z (0x1a) for EOF. > > c:\> copy con test.txt > hello > ^Z > c:\> IIRC, ctrl-Z is not used _in_files_ to represent EOF. Only when text is being entered at the console. > *nix usually uses ctrl+D (0x04) as an EOF signal...and OS-X > being Unixish also uses the same. > > bash$ cat > test.txt > hello > ^D > bash$ That's just the tty line-discipline layer of the tty driver. When it sees Ctrl-D as the first thing on a "line", it closes the file descriptor causing the client to see an EOF. That feature in the line-discipline layer can be disabled or configured to use any other character. I suspect what the OP really needs to do is write a newline and then flush the stream. -- Grant Edwards grante Yow! I'm pretending that at we're all watching PHIL visi.comSILVERS instead of RICARDO MONTALBAN! -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
gel wrote: > Hi > I have written a python client server app that keeps an eye on > processes starting and ending on a client and makes decision on what to > do based on information from the server end. I want to run the client > end of the app more or less invisibly (no console) on the XP clients > when ever a users logs on. What would be the best way to get this > done? A bit more info on the purpose of the app... it is to act as a > licence server, where we have a limited number of licences for software > and the software installed on all PCs. The app will only allow a pre > defined number of clients to run the software at any one time. To run a python script without a console - use *.pyw extension. But from what you stated you perhaps don't want to do this. Whether you deploy this check as a service (through py2exe for example) or a straight script, the users may simply kill it if they want to bypass the check. Plus it is not common to use a seperate persistant process to check for licenses. A better way is to incorporate the check directly into the process of the software. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you get the name of a dictionary?
On Fri, 18 Aug 2006 11:45:05 -0700, Andy Terrel wrote: > here is an easy hack, I don't know if there is an explicit function. > > > for i in dir(): > if eval(i) == Banana: > print i Let's just hope that there is no way for black-hats to remotely inject code objects into your namespace: >>> class Killer: ... def __repr__(self): ... import os ... os.system('echo Do something evil...') ... return "Your system is 0wn3d" ... >>> x = Killer() Now x is sitting there in your namespace like a mine, just waiting for you to call eval('x'). Okay, so maybe it isn't the most likely security threat in the universe, but it is a reminder that eval() can have side-effects. In this specific instance, if repr() has a side-effect (e.g. an object that knows how many times it has been printed), so will your code. That's probably not a good thing to do. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Ravi Teja wrote: > gel wrote: > > Hi > > I have written a python client server app that keeps an eye on > > processes starting and ending on a client and makes decision on what to > > do based on information from the server end. I want to run the client > > end of the app more or less invisibly (no console) on the XP clients > > when ever a users logs on. What would be the best way to get this > > done? A bit more info on the purpose of the app... it is to act as a > > licence server, where we have a limited number of licences for software > > and the software installed on all PCs. The app will only allow a pre > > defined number of clients to run the software at any one time. > > To run a python script without a console - use *.pyw extension. > > But from what you stated you perhaps don't want to do this. Whether you > deploy this check as a service (through py2exe for example) or a > straight script, the users may simply kill it if they want to bypass > the check. Plus it is not common to use a seperate persistant process > to check for licenses. A better way is to incorporate the check > directly into the process of the software. The reason for the a seperate persistant check is because it will be used to enable software to be installed in whole lab of PCs but only allow a predifined number to run the software at any time one time. And then when a user stop using the software a licence will become available to for someone else on the same or another PC to use the software. The reason that the process of the software being check is not used is because it will be used for software written by other people. I hope this makes what and why a little clearer. Let me know if you think that I have misunderstoood you. -- http://mail.python.org/mailman/listinfo/python-list
Re: write eof without closing
Grant Edwards <[EMAIL PROTECTED]> wrote: ... > IIRC, ctrl-Z is not used _in_files_ to represent EOF. Only > when text is being entered at the console. Easy to test, if you have Windows: >>> n='foo.txt' >>> s='ba\r\n'+chr(26)+'bo\r\r' >>> open(n,'wb').write(s) >>> ss=open(n).read() >>> ss 'ba\n' As you see, in _text_ files on Windows a control-Z (char(26), AKA '\x1a') does indeed represent "end of file" -- a convention going back to CP/M (which lacked metadata to represent file length except in multiples of 256 characters, if I recall correctly) and is still followed by Windows (and by Python running on Windows). Nevertheless I doubt it would help the original poster -- I think, like /F and you, that a line-end and flush may be what he needs. Alex -- http://mail.python.org/mailman/listinfo/python-list
Is there a python system to admin MySQL database online?
Just like the phpMySQLadmin? Thanks for reply! -- http://mail.python.org/mailman/listinfo/python-list
Re: pickling or xml or other?
You could use a python file and use the builtin import facility to read in configurations. from http://dirtsimple.org/2004/12/python-is-not-java.html ... in Python, more often than not, code is easier to write than XML. And Python can process code much, much faster than your code can process XML. (Not only that, but you have to write the XML processing code, whereas Python itself is already written for you.) placid wrote: > Hi all, > > I have an application were i want the user to "configure" some settings > which are variables within different classes. > > My question is should i just pickle out these variables to a file in > some particular order then read it back. Or use xml to save the config > values ? Which one scales better if settings increase? > > Other sugestions? > > -Cheers -- http://mail.python.org/mailman/listinfo/python-list
A Editor Feature for Extending Selection based on Language Syntax
can anyone give me a guide about writing a short elisp function? (for non-emacs readers, this message will describe a editor feature i think will be very beneficial to spread this concept.) i want to write a function such that, when run, highlight a region between the nearest left and right delimiters. Delimiters are any of parenthesis, square brackets, or single and double quotes etc. When the function is run again, it extends the selection to the next enclosing delimiters. So, in this way, a user can repeatedly press a keyboard shortcut and extend the selection. This is feature of BBEdit/TextWrangler on the Mac, which extend selection to the nearest outer parenthesis. This is also a feature of the Mathematica editor, which actually extend selection to the nearest syntactical unit in the language, not just paired delimiters. What i wanted this for is mostly in editing HTML/XML, where one press can select the content, another press will include the enclosing tags, another press extends the selection to the next outer content, and another press include that tags too, and so on. I'm a elisp newbie. Here's a simple code i have so far: (defun d () "extend selection to nearest enclosing delimiters" (interactive) (skip-chars-backward "^<>()“”{}[]") (push-mark) (skip-chars-forward "^<>()“”{}[]") (exchange-point-and-mark 1) ) ... i think i have quite a lot to go... I think this would be a great feature for any mode, where the a keypress will highlight more syntactical units in any language's mode. For example, suppose in C-like language: function f (arg1, arg2) { line1; line2; } if the cursor is at arg1, then first press will highlight the content of the args, another press includes the parens, another press will include the whole function. If the cursor is at line1, then it selects that word in the line, then the line, then the whole function def body, then including {}, then the whole function... etc in many languages. For a xml language example, suppose we have this RSS/Atom example: Gulliver's Travels tag:xahlee.org,2006-08-21:030437 2006-08-20T20:04:41-07:00 Annotated a chapter of Gulliver's Travels If the cursor is inside a tag's enclosing content, say, on the T in Gulliver's Travels inside the tag, then the repeated extension is obvious. But however, suppose the cursor is at t in the “alternate” inside the “link” tag, then it would first select the whole “alternate” word, then the whole “rel="alternate"”, then the whole link tag, then the whole content of the entry tag, then including the “” tags itself. (in short, the selection extends according to the language's syntax tree) Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: A Editor Feature for Extending Selection based on Language Syntax
On 20 Aug 2006 21:49:45 -0700, Xah Lee <[EMAIL PROTECTED]> wrote: > can anyone give me a guide about writing a short elisp function? (for > non-emacs readers, this message will describe a editor feature i think > will be very beneficial to spread this concept.) > > i want to write a function such that, when run, highlight a region > between the nearest left and right delimiters. Delimiters are any of > parenthesis, square brackets, or single and double quotes etc. When the > function is run again, it extends the selection to the next enclosing > delimiters. > > So, in this way, a user can repeatedly press a keyboard shortcut and > extend the selection. This functionality can be found in NewEdit (http://wiki.woodpecker.org.cn/moin/NewEdit), first put the caret in middle of delimeters, such as ''""(){}[], then press Ctrl+E, the text between delimeters will be selected. And there are two direction of selection, left first and right first(Ctrl+Shift+E). If you press Ctrl+Alt+E again, the the delimeters will be selected. > > This is feature of BBEdit/TextWrangler on the Mac, which extend > selection to the nearest outer parenthesis. This is also a feature of > the Mathematica editor, which actually extend selection to the nearest > syntactical unit in the language, not just paired delimiters. > > What i wanted this for is mostly in editing HTML/XML, where one press > can select the content, another press will include the enclosing tags, > another press extends the selection to the next outer content, and > another press include that tags too, and so on. > NewEdit can not support this feature now. -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit -- http://mail.python.org/mailman/listinfo/python-list
Re: Input from the same file as the script
you can (ab)use doc strings. See the doctest module for an example. -- http://mail.python.org/mailman/listinfo/python-list
Re: istep() addition to itertool? (Was: Re: Printing n elements per line in a list)
Rhamphoryncus wrote: > I've run into this problem a few times, and although many solutions > have been presented specifically for printing I would like to present a > more general alternative. [snip interesting istep function] > Would anybody else find this useful? Maybe worth adding it to itertool? yeah, but why on earth did you make it so complicated? def istep(iterable, step): a=[] for x in iterable: if len(a) >= step: yield a a=[] a.append(x) if a: yield a -- - Justin -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble using "\" as a string
OriginalBrownster wrote: > i want this because using python I am pulling in filenames from a > mac..thus they are "/" in the pathways..and i want to .split it at the > "/" to obtain the filename at the end...but its proving diffucult with > this obstacle in the way. sounds like you want import posixpath posixpath.basename(path) assuming you are on a windows box,otherwise the normal os.path.basename will do it. -- - Justin -- http://mail.python.org/mailman/listinfo/python-list
Reported (was Re: A Editor Feature for Extending)
"Xah Lee" <[EMAIL PROTECTED]> wrote: Let's see how fast we can drop you from another hosting provider :-D. -- JohnExperienced Perl programmer: http://castleamber.com/ Perl help, tutorials, and examples: http://johnbokma.com/perl/ -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] PyYAML-3.04: YAML parser and emitter for Python
I'll be out of the office until approximately August 20th. If you have any questions, please email [EMAIL PROTECTED] -- David Wahler -- http://mail.python.org/mailman/listinfo/python-list
Re: Subject: ANN: pycairo release 1.2.2 now available
I'll be out of the office until approximately August 20th. If you have any questions, please email [EMAIL PROTECTED] -- David Wahler -- http://mail.python.org/mailman/listinfo/python-list