Re: Splitting a string
Nico Grubert wrote: > I'd like to split a string where 'and', 'or', 'and not' occurs. > > Example string: > s = 'Smith, R. OR White OR Blue, T. AND Black AND Red AND NOT Green' > > I need to split s in order to get this list: > ['Smith, R.', 'White', 'Blue, T.', 'Back', 'Red', 'Green'] > > Any idea, how I can split a string where 'and', 'or', 'and not' occurs? try re.split: >>> s = 'Smith, R. OR White OR Blue, T. AND Black AND Red AND NOT Green' >>> import re >>> re.split("AND NOT|AND|OR", s) # look for longest first! ['Smith, R. ', ' White ', ' Blue, T. ', ' Black ', ' Red ', ' Green'] to get rid of the whitespace, you can either use strip >>> [w.strip() for w in re.split("AND NOT|AND|OR", s)] ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'Green'] or tweak the split pattern somewhat: >>> re.split("\s*(?:AND NOT|AND|OR)\s*", s) ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'Green'] to make the split case insensitive (so it matches "AND" as well as "and" and "AnD" and any other combination), prepend (?i) to the pattern: >>> re.split("(?i)\s*(?:and not|and|or)\s*", s) ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'Green'] to keep the separators, change (?:...) to (...): >>> re.split("(?i)\s*(and not|and|or)\s*", s) ['Smith, R.', 'OR', 'White', 'OR', 'Blue, T.', 'AND', 'Black', 'AND', 'Red', 'AND NOT', 'Green'] hope this helps! -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a string
Take a look at: http://docs.python.org/lib/node115.html#l2h-878 So I would try something like: pat = re.compile(r" (?:AND|OR|AND NOT) ") pat.split(string) Compile the regular expression with re.IGNORECASE if you like. Nico Grubert wrote: > Dear Python users, > > I'd like to split a string where 'and', 'or', 'and not' occurs. > > Example string: > s = 'Smith, R. OR White OR Blue, T. AND Black AND Red AND NOT Green' > > I need to split s in order to get this list: > ['Smith, R.', 'White', 'Blue, T.', 'Back', 'Red', 'Green'] > > Any idea, how I can split a string where 'and', 'or', 'and not' occurs? > > > Thank you very much in advance, > Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
Roy Smith wrote: > Erik Max Francis <[EMAIL PROTECTED]> wrote: >> (A 2-tuple is an "ordered pair" in mathematics.) If a 2-tuple is a >> pair, then it would seem to follow that a 1-tuple is a single. > > Yeah, but an *ordered* single :-) > > A more interesting question is what do you call ()? A none-tuple? empty? -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: hard disk activity
On 13 Feb 2006 13:13:51 -0800 Paul Rubin <"http://phr.cx"@NOSPAM.invalid> wrote: > "VSmirk" <[EMAIL PROTECTED]> writes: > > Aweseme!!! I got as far as segmenting the large file on > > my own, and I ran out of ideas. I kind of thought about > > checksum, but I never put the two together. > > > > Thanks. You've helped a lot > > The checksum method I described works ok if bytes change > in the middle of the file but don't get inserted (piecs of > the file don't move around). If you insert on byte in the > middle of a 1GB file (so it becomes 1GB+1 byte) then all > the checksums after the middle block change, which is no > good for your purpose. But of course, the OS will (I hope) give you the exact length of the file, so you *could* assume that the beginning and end are the same, then work towards the middle. Somewhere in between, when you hit the insertion point, both will disagree, and you've found it. Same for deletion. Of course, if *many* changes have been made to the file, then this will break down. But then, if that's the case, you're going to have to do an expensive transfer anyway, so expensive analysis is justified. In fact, you could proceed by analyzing the top and bottom checksum lists at the point of failure -- download that frame, do a byte by byte compare and see if you can derive the frameshift. Then compensate, and go back to checksums until they fail again. Actually, that will work just coming from the beginning, too. If instead, the region continues to be unrecognizeable to the end of the frame, then you need the next frame anyway. Seems like it could get pretty close to optimal (but we probably are re-inventing rsync). Cheers, Terry -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a string
On 2/14/06, Nico Grubert <[EMAIL PROTECTED]> wrote: > Dear Python users, > > I'd like to split a string where 'and', 'or', 'and not' occurs. > > Example string: > s = 'Smith, R. OR White OR Blue, T. AND Black AND Red AND NOT Green' > > I need to split s in order to get this list: > ['Smith, R.', 'White', 'Blue, T.', 'Back', 'Red', 'Green'] > > Any idea, how I can split a string where 'and', 'or', 'and not' occurs? RE module can do this: >>> import re >>> s = 'Smith, R. OR White OR Blue, T. AND Black AND Red AND NOT Green' >>> r = re.split('(?i)\s*(and\s*not|and|or)\s*', s) >>> [x[1] for x in enumerate(r) if (x[0]+1) % 2] ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'Green'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a string
Dylan Moreland wrote: > So I would try something like: > > pat = re.compile(r" (?:AND|OR|AND NOT) ") > pat.split(string) footnote: this yields: ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'NOT Green'] (the | operator picks the first (leftmost) alternative that results in an overall match.) -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
Hmm, I've found a term for a large tuple, a muckle: http://www.google.co.uk/search?hl=en&q=define%3Amuckle&btnG=Search&meta= Definitions of muckle on the Web: * batch: (often followed by `of') a large number or amount or extent; "a batch of letters"; "a deal of trouble"; "a lot of money"; "he made a mint on the stock market"; "it must have cost plenty" wordnet.princeton.edu/perl/webwn - Pad -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a string
Woops! Thanks for the correction. I was assuming greediness for some reason. Fredrik Lundh wrote: > Dylan Moreland wrote: > > > So I would try something like: > > > > pat = re.compile(r" (?:AND|OR|AND NOT) ") > > pat.split(string) > > footnote: this yields: > > ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'NOT Green'] > > (the | operator picks the first (leftmost) alternative that results in an > overall match.) > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a string
Fredrik Lundh wrote: re.split("(?i)\s*(?:and not|and|or)\s*", s) > ['Smith, R.', 'White', 'Blue, T.', 'Black', 'Red', 'Green'] This fails for people with nasty names: >>> s = "James White or Andy Grove and Jack Orr and not James Grand" >>> re.split("(?i)\s*(?:and not|and|or)\s*", s) ['James White', '', 'y Grove', 'Jack', 'r', 'James Gr', ''] Here is an alternative: >>> [s.strip() for s in re.split(r"(?i)\b(?:and|or|not)\b", s) if s.strip()] ['James White', 'Andy Grove', 'Jack Orr', 'James Grand'] Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
(dupple, supple, zupple) = (2,1,0) # :-) -- http://mail.python.org/mailman/listinfo/python-list
RE: How to get DVD Drive Name?
[Robot] > How to get the DVD Drive name with Python? Since you're not giving many clues with that question, I'm going to guess that you're on Windows and that you want to know which of your drives is the DVD? Or, possibly, what the physical DVD description is. Assuming that's the case, you should be able to do something with WMI. I don't have a DVD on this machine, but I suggest you look at the Win32_CDROMDrive class, and probably at the Id or Drive fields. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a string
Nico Grubert <[EMAIL PROTECTED]> writes: > I'd like to split a string where 'and', 'or', 'and not' occurs. Other people have suggested how to do this splitting. But don't you really want a parser? -- http://mail.python.org/mailman/listinfo/python-list
Python / Apache / MySQL
Hi All I want to build an Website using Apache / Python and MySQL. I dont want to spend to much time hacking html. I'm looking for some recommendations e.g. should I be using mod_python ? whats the best module for mysql ? any suggestings so I could get my site up in a day ? [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop Backwards
Dave wrote: > This should be simple, but I can't get it: > > How do you loop backwards through a list? > > For example, in, say, Javascript: > > for (var i = list.length - 1; i >=0; i--) { > do_stuff() > } > > I mean, I could reverse the list, but I don't want to. I want it to > stay exactly the same, but I want to start at the end and end at the > beginning. for item in reversed(alist): do_something_with(item) or (more perlish at first sight): for item in alist[::-1]: do_something_with(item) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
[Terry Hancock] > So what's a 1-element tuple, anyway? A "mople"? "monople"? > It does seem like this lopsided pythonic creature (1,) ought > to have a name to reflect its ugly, newbie-unfriendly > nature. It's a "trip-you-uple", which you can pronounce anyway you like ;-) -- alan kennedy -- email alan: http://xhaus.com/contact/alan -- http://mail.python.org/mailman/listinfo/python-list
Re: Jedit
I've often wondered this. I was thinking more along the lines of a scriptable Python editor like Emacs. The only thing I've noticed is: CUTE - *nix only. - (http://cute.sourceforge.net/) PyEditor - (http://www.rexx.com/~dkuhlman/pyeditor_howto.html) ViImproved - (http://wiki.python.org/moin/ViImproved) PythonCardEditor - (http://wiki.wxpython.org/index.cgi/PythonCardEditor) On 2/14/06, ziggy <[EMAIL PROTECTED]> wrote: > Just wondering if there is something out there like Jedit, but written > in python ( not just supporting, but actually written in it.. ) > > Nothing large like Stanzi's or Boa.. Just something quick and simple, > with code completion, and a debugger.. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
vpr wrote: > Hi All > > I want to build an Website using Apache / Python and MySQL. Good choice, good choice, bad choice... Why not using PostgresSQL (if you need a *real* RDBMS) or SQLite (if you don't...) > I dont want to spend to much time hacking html. I'm looking for some > recommendations > e.g. should I be using mod_python ? mod_python is mostly a 'low-level' Apache API binding. Better use a higher-level tool on top of it. AFAICT, Myghty might be of some help here. > whats the best module for mysql ? Psycopg ?-) oops, sorry > any suggestings so I could get my site up in a day ? Look for Myghty, Pylons (built on Mygthy), or Django. There's also Turbogears, but it's based on CherryPy, so you won't really take advantage of mod_python's Apache integration. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
Alan Kennedy wrote: > [Terry Hancock] >> So what's a 1-element tuple, anyway? A "mople"? "monople"? >> It does seem like this lopsided pythonic creature (1,) ought >> to have a name to reflect its ugly, newbie-unfriendly >> nature. > > It's a "trip-you-uple", which you can pronounce anyway you like ;-) All I hear there is "triple you up," which is good if you're in a poker tournament, which I suppose tells you where my mind has been lately. -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis If there must be trouble let it be in my day, that my child may have peace. -- Thomas Paine -- http://mail.python.org/mailman/listinfo/python-list
Xah's Edu Corner: accountability & lying thru the teeth
here's a site: http://www.longbets.org/bets that takes socially important predictions. I might have to enter one or two. i longed for such a accountable predictions for a long time. Usually, some fucking fart will do predictions, but the problem is that it's not accountable. So, lots fuckhead morons in the IT industry will shout about their opinions on society and technology such as for example “Microsoft will fall within a decade” or “linux will rule”, or some technology issues such as “singularity”. But the problem is, any moron can sound big when there's no accountability associated with their cries. This website, at least makes it possible to do accountable opinions. (in the form of mandatory monetary donations) But i really wished for a mechanism, so that any fuckhead tech geekers with their loud cries will hurt badly when they open their mouths in public with wantonness. For more info about the longbets.org site, see: http://en.wikipedia.org/wiki/Long_Now_Foundation Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic gui format?
DH wrote: > Bruno Desthuilliers wrote: > >>> I am currently seeking for pythonic alternative for XML. >> >> >> A pretty obvious one is dicts and lists. What about (Q&D): > > > That's like JSON: http://www.json.org/example.html No, it's pure Python. It happens that JSON looks pretty close to Python, but that's another point. And BTW, you should have read the whole post - I was *also* mentionning JSON as a possible alternative to XML. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's Edu Corner: accountability & lying thru the teeth
Xah Lee wrote: > here's a site: http://www.longbets.org/bets that takes socially > important predictions. I might have to enter one or two. > > i longed for such a accountable predictions for a long time. Usually, > some fucking fart will do predictions, but the problem is that it's not [...] OMG, he's back. I predict, Xah will haunt us for years to come. -- Suffering from Gates-induced brain leakage... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
On Tue, 14 Feb 2006 10:32:34 +0100, Sybren Stuvel wrote (in article <[EMAIL PROTECTED]>): > I second Bruno: swap MySQL in favour of PostgreSQL. And the reason is ?? (apart from PostgreSQL being larger and more complete, what are the differences for "simple" usage?) jem -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's Edu Corner: accountability & lying thru the teeth
Xah Lee <[EMAIL PROTECTED]> wrote in comp.lang.perl.misc: > ...a mechanism, so that any fuckhead tech geekers with their > loud cries will hurt badly when they open their mouths in public... Yeah, good idea! Anno -- If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Issues installing MySQL-python-0.3.5
Sorry for the duplicate email, Keith. [EMAIL PROTECTED] wrote: > Hi, > > I am trying to use the Python MySQL APIs and have been attempting to > install the above software. > > I am using MySQL 5.0.18-standard with Python 2.4.1 > > I get errors on the build. Some searching showed that one of the modules > I was having issues with now has less arguments in my version of python, > but I can't seem to fix the following error: > > *** > _mysqlmodule.c: In function ‘_mysql_ConnectionObject_shutdown’: > _mysqlmodule.c:1019: error: too few arguments to function > ‘mysql_shutdown’ > *** > Should I just give up on MySQL-python-0.3.5 ? [...] This release is almost 5 years old. Where did you dig it out from? ;-) http://dustman.net/andy/python/MySQLdb_obsolete/0.3.5 """ MySQLdb module 0.3.5 OBSOLETE Python Interface to MySQL Stability: Perfect in every way Released: 2001-03-25 00:00 UTC Notes NOTICE: This version works fine, but I strongly recommend 0.9.0 or newer, available from SourceForge. """ I'd try MySQLdb 1.2.0, which *might* work, according to its README: """ * MySQL-5.0 and newer are not currently supported, but might work. * MaxDB, formerly known as SAP DB (and maybe Adabas D?), is a completely different animal. Use the sapdb.sql module that comes with MaxDB. """ -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: 88k regex = RuntimeError
> I assume it's hitting some limit, but don't know where the limit is to > remove it. I tried stepping into it repeatedly with Komodo, but didn't > see the problem. That's because it is buried in the C-library that is the actual implementation. There has been a discussion about this a few weeks ago - and AFAIK there isn't much you can do about that. > Suggestions? Yes. Don't do it :) After all, what you do is nothing but a simple word-search. If I had that problem, my naive approach would be to simply tokenize the sources and look for the words in them being part of your function-name-set. A bit of statekeeping to keep track of the position, and you're done. Check out pyparsing, it might help you doing the tokenization. I admit that the apparent ease of the regular expression would have lured me into the same trap. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
Kalle Anke wrote: > On Tue, 14 Feb 2006 10:32:34 +0100, Sybren Stuvel wrote > (in article <[EMAIL PROTECTED]>): > > >>I second Bruno: swap MySQL in favour of PostgreSQL. > > > And the reason is ?? (apart from PostgreSQL being larger and more complete, > what are the differences for "simple" usage?) The reason is mostly that either you need a real, full-blown, rock-solid RDBMS - which MySQL is definitively not - or you dont - in which case SQLite is probably a much more lightweight and agile solution. My 2 cents -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
is socket thread safe?
thread1: while 1: buf = s.read() process(buf) thread2: while 1: buf = getdata() s.write(buf) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
vpr enlightened us with: > I want to build an Website using Apache / Python and MySQL. I second Bruno: swap MySQL in favour of PostgreSQL. > e.g. should I be using mod_python ? You could use my framework based on mod_python and Cheetah. I find it really easy to use. Check out http://www.unrealtower.org/webengine > whats the best module for mysql ? I'd use SQLObject. It can handle MySQL (if you really want to stick to it), SQLite and PostgreSQL. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: get output of cmd-line command under MS windows
"calmar" wrote: > that was good, but on python2.4 > > subprocess is GREAT! e.g.: > > pipe = subprocess.Popen(tot, stdout=subprocess.PIPE,\ > stderr=subprocess.PIPE, shell=False) > message = pipe.stdout.read() > error = pipe.stderr.read() footnote: subprocess is available for Python 2.2 and later, from http://www.lysator.liu.se/~astrand/popen5/ -- http://mail.python.org/mailman/listinfo/python-list
Re: cyclic data structures
John Salerno wrote: > I'm having some slight trouble understanding exactly why this creates an > infinite loop: > > L = [1, 2] > L.append(L) I tried this with Python 2.3.5 and it handles this tailbiter in a very pleasantly surprising way: >>> l = [ 0, 1 ] >>> l.append( l ) >>> l [0, 1, [...]] >>> l[2] [0, 1, [...]] >>> l[2][2][2][2][2][2][2][0] 1 The [...] I have never seen before anywhere, is it documented? -- -- Ewald -- http://mail.python.org/mailman/listinfo/python-list
Re: 88k regex = RuntimeError
Why don't you create a regex that finds for you all C function declarations (and which returns you the function-names); apply re.findall() to all files with that regex; and then check those funtion-names against the set of allSupported? You might even be able to find a regex for C funtion declarations on the web. Your gAllSupported can be a set(); you can then create the intersection between gAllSupported and the function-names found by your regex. Cheers, --Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie
LittlePython wrote: > Is this a good place to post python questions from newbie's, or would you > suggest another board? The best place to ask newbie questions is the Tutor mailing list. Go to http://mail.python.org/mailman/listinfo/tutor to subscribe. Check out the archives and you'll see how great it is. Besides the fact that there are several guys who are both very good at Python, good at explaining, and tolerant with newbie questions and mistakes, you'll see much less of those sidetracking long threads you often see in comp.lang.python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
Kalle Anke wrote: > I always thought that a SQLlite database "belonged" to a single process, can > a database be used by several processes? Depending on what you mean by "belong", that's either true or false. Certainly multiple processes can access a SQLite database, although as the documentation clearly describes if those processes are making _frequent updates_ it's not the best solution and another database might be more suitable. > Let's say I would build a small web application that would be used by a small > number of people/processes and it wouldn't be anything fancy just basic > "selects". What would be the choice for this? SQLite. (As but one option, but "just basic selects" is certainly included in the set of suitable conditions for SQLite use.) > What about speed? I've always had the impression that while PostgreSQL is > more complete than MySQL it's also slower. Don't optimize prematurely? If you use something like SQLObject, or any other means of abstracting yourself away from the details of a specific datbase, you won't be particularly tied to it if you decide you need improved performance, or sophistication, or whatever. > Sorry, if these are really stupid questions but ... They're not. -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop Backwards
Em Ter, 2006-02-14 às 10:08 +0100, bruno at modulix escreveu: > for item in reversed(alist): > do_something_with(item) > > or (more perlish at first sight): > > for item in alist[::-1]: > do_something_with(item) No "or" here. The [::-1] version creates a whole new list in memory, it's silly to believe both will behave equally (well, strictly speaking they will, but one will use twice more memory than the other). -- "Quem excele em empregar a força militar subjulga os exércitos dos outros povos sem travar batalha, toma cidades fortificadas dos outros povos sem as atacar e destrói os estados dos outros povos sem lutas prolongadas. Deve lutar sob o Céu com o propósito primordial da 'preservação'. Desse modo suas armas não se embotarão, e os ganhos poderão ser preservados. Essa é a estratégia para planejar ofensivas." -- Sun Tzu, em "A arte da guerra" -- http://mail.python.org/mailman/listinfo/python-list
Re: listing attributes
On Mon, 13 Feb 2006 22:18:56 -0500, Peter Hansen wrote: > Thomas Girod wrote: >> I'm trying to get a list of attributes from a class. The dir() function >> seems to be convenient, but unfortunately it lists to much - i don't >> need the methods, neither the built-in variables. >> >> In fact, all my variables are referencing to objects of the same type. >> Can anyone suggest me a way to get this list of variables ? > > Does the __dict__ attribute help you? (Try viewing obj.__dict__ at the > interpreter prompt and see if it has what you expect. > obj.__dict__.keys() would be just the names of those attributes.) >>> class Parrot(object): ... ATTR = None ... def method(self): ... return None ... >>> dir(Parrot) ['ATTR', '__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'method'] >>> Parrot.__dict__.keys() ['__module__', 'ATTR', 'method', '__dict__', '__weakref__', '__doc__'] So I guess the answer to that question is, while __dict__ gives less information than dir, it still gives too much. The thing to remember is that methods are attributes too, so it is a little hard to expect Python to magically know which attributes you want to see and which you don't. Although, I don't think it is too much to expect Python to distinguish methods from non-method attributes. However it is easy to use introspection to get what you need. def introspect(obj): attributes == dir(obj) # get rid of attributes that aren't the right type attributes = [a for a in attributes if \ type(getattr(obj, a)) == type(obj)] # or filter any other way you like return attributes -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: 88k regex = RuntimeError
jodawi wrote: > I need to find a bunch of C function declarations by searching > thousands of source or html files for thousands of known function > names. My initial simple approach was to do this: > > rxAllSupported = re.compile(r"\b(" + "|".join(gAllSupported) + r")\b") > # giving a regex of \b(AAFoo|ABFoo| (uh... 88kb more...) |zFoo)\b Maybe you can be more clever about the regex? If the names above are representative then something like r'\b(\w{1,2})Foo\b' might work. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
Kalle Anke enlightened us with: > What about speed? I've always had the impression that while > PostgreSQL is more complete than MySQL it's also slower. For simple queries, I believe (no real knowledge here) MySQL is indeed faster. One of the problems I have with MySQL is that it doesn't support foreign keys nor transactions on the default table format. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
On Tue, 14 Feb 2006 11:19:11 +0100, bruno at modulix wrote (in article <[EMAIL PROTECTED]>): > The reason is mostly that either you need a real, full-blown, rock-solid > RDBMS - which MySQL is definitively not - or you dont - in which case > SQLite is probably a much more lightweight and agile solution. Stupid questions (I know very little about databases): I always thought that a SQLlite database "belonged" to a single process, can a database be used by several processes? Let's say I would build a small web application that would be used by a small number of people/processes and it wouldn't be anything fancy just basic "selects". What would be the choice for this? What about speed? I've always had the impression that while PostgreSQL is more complete than MySQL it's also slower. Sorry, if these are really stupid questions but ... jem -- http://mail.python.org/mailman/listinfo/python-list
Re: get output of cmd-line command under MS windows
On 2006-02-08, Bernard Lebel <[EMAIL PROTECTED]> wrote: Hi Bernhard, > You should give a go to os.popen( ). Article > 6.1.2 and 6.1.3 in the Python Library doc. > that was good, but on python2.4 subprocess is GREAT! e.g.: pipe = subprocess.Popen(tot, stdout=subprocess.PIPE,\ stderr=subprocess.PIPE, shell=False) message = pipe.stdout.read() error = pipe.stderr.read() thanks all, calmar -- calmar (o_ It rocks: LINUX + Command-Line-Interface //\ V_/_ http://www.calmar.ws -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
On Tue, 14 Feb 2006 12:04:45 +0100, Peter Hansen wrote (in article <[EMAIL PROTECTED]>): > SQLite. (As but one option, but "just basic selects" is certainly > included in the set of suitable conditions for SQLite use.) I've considered to use SQLite for an application but for completely different reasons ... hmm, I should perhaps consider SQLite for some other ideas I have also ... > Don't optimize prematurely? If you use something like SQLObject, or any > other means of abstracting yourself away from the details of a specific > datbase, you won't be particularly tied to it if you decide you need > improved performance, or sophistication, or whatever. That's true ... I was thinking in general terms here (a couple of people I know handles huge data sets, genome data type of things, and in their case speed is very important) -- http://mail.python.org/mailman/listinfo/python-list
file names longer than MAX_PATH under Windows 2003
Hello. I try to open file with pathname length 282 bytes: E:\files\..\something.dat On MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp) described method to access files with path length up to 32000 bytes: just add prefix \\?\ to file name. But when I try to pass prefixed name to file(), I get the same result as when I don't add the prefix: file not found. May be Python just doesn't support long unicode filenames? Is there way to open such files? -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging hangs thread after detaching a StreamHandler's terminal
[EMAIL PROTECTED] wrote: > Hi all, > > After many hours, I think I've found a bug in the logging module! > > If you add a (stdout) StreamHandler to a logger, then detach the > terminal for that stdout, subsequent calls to log() will hang the > calling thread. > > To reproduce this, write the following scripts (this was a small test > case I came up with - maybe there's something simpler): > [scripts snipped] > Run ./tryhup.bash. It will sit in an idle spin. Monitor the files > /tmp/hup.out and /tmp/lup.out. Hit Ctrl-C on tryhup to kill it. The > python process is still running, but is stalled (the .out files are no > longer changing). > > If you remove the above labeled line, however, this doesn't happen. > > Can anybody please acknowledge this bug? Any temporary workarounds to > this problem? Thanks in advance for looking into this and for hearing > me in! I tried these scripts on Ubuntu 5.10 and did not see the problem you are experiencing. The script continues to run (printing dashes to the console), and hup.out/lup.out are also updated continuously. What's your configuration? Also, note that the logging module merely opens the stream passed to the StreamHander for output, so check if in your configuration you get a hang just doing a write to sys.stderr. Best regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: 88k regex = RuntimeError
jodawi wrote: > I need to find a bunch of C function declarations by searching > thousands of source or html files for thousands of known function > names. My initial simple approach was to do this: > > rxAllSupported = re.compile(r"\b(" + "|".join(gAllSupported) + r")\b") > # giving a regex of \b(AAFoo|ABFoo| (uh... 88kb more...) |zFoo)\b > > for root, dirs, files in os.walk( ... ): > ... > for fileName in files: > ... > filePath = os.path.join(root, fileName) > file = open(filePath, "r") > contents = file.read() > ... > result = re.search(rxAllSupported, contents) > > but this happens: > > result = re.search(rxAllSupported, contents) > File "C:\Python24\Lib\sre.py", line 134, in search > return _compile(pattern, flags).search(string) > RuntimeError: internal error in regular expression engine > > I assume it's hitting some limit, but don't know where the limit is to > remove it. I tried stepping into it repeatedly with Komodo, but didn't > see the problem. > > Suggestions? One workaround may be as easy as wanted = set(["foo", "bar", "baz"]) file_content = "foo bar-baz ignored foo()" r = re.compile(r"\w+") found = [name for name in r.findall(file_content) if name in wanted] print found Peter -- http://mail.python.org/mailman/listinfo/python-list
Unexpected behaviour of getattr(obj, __dict__)
I came across this unexpected behaviour of getattr for new style classes. Example: >>> class Parrot(object): ... thing = [1,2,3] ... >>> getattr(Parrot, "thing") is Parrot.thing True >>> getattr(Parrot, "__dict__") is Parrot.__dict__ False I would have expected that the object returned by getattr would be the same object as the object returned by standard attribute access. This is true for some attributes, but not for __dict__. I don't know if there are other examples. Why is this? Is there some documentation I can read up about this? I've tried searching, but can't find anything useful. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
RE: file names longer than MAX_PATH under Windows 2003
[Sergey] | I try to open file with pathname length 282 bytes: | E:\files\..\something.dat | [... MS advise ...] just add prefix \\?\ to file name. | But when I try to pass prefixed name to file(), I get the | same result as when I don't add the prefix: file not found. With a file called c:\temp\test.txt, I successfully opened and read it like this: print open (r"\\?\C:\temp\test.txt").read () So the basic functionality works. I didn't artificially generate a long path to see if there's a problem in that direction. But note that r prefix to the string. Is it possible that your string didn't include it? If not, then the backslash character which Windows uses as a separator can be stolen by Python which sees it as an escaping character. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a string
Nico Grubert wrote: > I'd like to split a string where 'and', 'or', 'and not' occurs. > Example string: > s = 'Smith, R. OR White OR Blue, T. AND Black AND Red AND NOT Green' Here is a solution without using the re module: s.replace(' AND NOT ', ' OR ').replace(' AND ', ' OR ').split(' OR ') -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: is socket thread safe?
[EMAIL PROTECTED]: >[code] I certainly expect socket to be threadsafe. I use it (via urllib2/httplib) in a multithreaded program, that runs fine with Python 2.3 and 2.4 on both Windows XP and Linux. -- René Pijlman -- http://mail.python.org/mailman/listinfo/python-list
Re: file names longer than MAX_PATH under Windows 2003
"Tim Golden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] [Sergey] >But note that r prefix to the string. Is it possible >that your string didn't include it? If not, then the >backslash character which Windows uses as a separator >can be stolen by Python which sees it as an escaping >character. It's ok with backslashes, I don't use r'', but double them so string is correct: >>> print c \\?\e:\files\ -- http://mail.python.org/mailman/listinfo/python-list
Re: Cygwin IDLE has no menu bar
Steve, On Mon, Feb 13, 2006 at 11:14:03PM -0500, Steve Holden wrote: > I just wondered whether anyone has seen this problem: Yes, this is a known problem: http://sf.net/tracker/?func=detail&atid=105470&aid=786827&group_id=5470 > and fixed it. Unfortunately, no. Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6 -- http://mail.python.org/mailman/listinfo/python-list
RE: file names longer than MAX_PATH under Windows 2003
[Sergey] | "Tim Golden" <[EMAIL PROTECTED]> wrote in | message news:[EMAIL PROTECTED] | [Sergey] | | >But note that r prefix to the string. Is it possible | >that your string didn't include it? If not, then the | >backslash character which Windows uses as a separator | >can be stolen by Python which sees it as an escaping | >character. | | It's ok with backslashes, I don't use r'', but double them so | string is correct: | >>> print c | \\?\e:\files\ Not to state the obvious, but can you cut-and-paste that long string (the one starting with \\?\e:\...) from the Python interpreter into the [S]tart [R]un [O]pen field to see what comes up? I'm just trying to make sure of the most straightforward fact: that the file you've got there definitely does exist! TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of getattr(obj, __dict__)
Steven D'Aprano wrote: > I came across this unexpected behaviour of getattr for new style classes. > Example: > > class Parrot(object): > > ... thing = [1,2,3] > ... > getattr(Parrot, "thing") is Parrot.thing > > True > getattr(Parrot, "__dict__") is Parrot.__dict__ > > False hint: >>> getattr(object, '__dict__') -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: listing attributes
Steven D'Aprano wrote: > However it is easy to use introspection to get what you need. So just for completeness sake, what Thomas probably wants is the following: from types import MethodType def attributes(obj): return [attr for attr in dir(obj) if not attr.startswith('__') and not isinstance(getattr(obj, attr), MethodType)] # Example: class Parrot(object): ATTR = None join = ''.join # callable, but not a method of Parrot def aMethod(self): return ATTR print attributes(Parrot) # this gives: ['ATTR', 'join'] -- http://mail.python.org/mailman/listinfo/python-list
Re: file names longer than MAX_PATH under Windows 2003
On Tue, 14 Feb 2006 22:43:50 +1100, Steven D'Aprano wrote: > On Tue, 14 Feb 2006 14:29:44 +0300, Sergey wrote: > >> Hello. >> >> I try to open file with pathname length 282 bytes: >> E:\files\..\something.dat >> >> On MSDN >> (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp) >> described method to access >> files with path length >> up to 32000 bytes: just add prefix \\?\ to file name. >> But when I try to pass prefixed name to file(), I get the same result as >> when I don't add the prefix: file not found. May be Python >> just doesn't support long unicode filenames? >> Is there way to open such files? > > Backslashes have special meaning to Python and need to be escaped. If you > do this: > > f = file("E:\files\...\something.dat", "r") > > Python's string escape rules means you are actually trying to open the > file "E:files...something.dat" which doesn't exist. [slaps head] I seem to be a bit confused about string escaping rules. Only some backslashes have special meaning, the rest remain in the string. Sergey, you said UNICODE file names. Not just ordinary strings. Are you passing a unicode object to the function? f = file(u"E:\\files\\...\\something.dat", "r") -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: file names longer than MAX_PATH under Windows 2003
"Tim Golden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] [Sergey] >Not to state the obvious, but can you cut-and-paste that long >string (the one starting with \\?\e:\...) from the Python >interpreter into the [S]tart [R]un [O]pen field to see what >comes up? I'm just trying to make sure of the most straightforward >fact: that the file you've got there definitely does exist! I cannot do this: when I paste filename there, trail of filename is missing due to length limit in input line. But I strongly suppose that file exists as its name was get through os.listdir. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of getattr(obj, __dict__)
Steven D'Aprano wrote: > I came across this unexpected behaviour of getattr for new style classes. > Example: > > >>> class Parrot(object): > ... thing = [1,2,3] > ... > >>> getattr(Parrot, "thing") is Parrot.thing > True > >>> getattr(Parrot, "__dict__") is Parrot.__dict__ > False > > I would have expected that the object returned by getattr would be the > same object as the object returned by standard attribute access. The returned object is a wrapper created on-the-fly as needed. You've requested two of them and each wrapper has a different object id but wraps an identical source. Contemplate this for a bit: >>> class Parrot(object): thing = [1,2,3] def f(self): pass >>> getattr(Parrot, 'f') is getattr(Parrot, 'f') False >>> getattr(Parrot, '__dict__') is getattr(Parrot, '__dict__') False The reason why is evident when you check the object representation. It shows that your lookup returned a wrapper: >>> getattr(Parrot, 'f')# creates a function wrapper >>> getattr(Parrot, '__dict__') # creates a dictionary wrapper IOW, attribute lookup can do more than just return the result of a straight-lookup. The underlying mechanism is a deep and interesting subject. If you want to know more, try this link: http://users.rcn.com/python/download/Descriptor.htm Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: file names longer than MAX_PATH under Windows 2003
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Are you passing a unicode object to the function? > > f = file(u"E:\\files\\...\\something.dat", "r") I pass variable c into functions: >>> c u'.\\e:\\files\\\u041f\u0420\u041e\u0414\u041e \u041c\u0435\u043d\u0435\u043 [many unicode chars skipped] 44b\u0439_\u0411\u044e\u0434\u0436\u0435\u0442.xls' -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic gui format?
Bruno Desthuilliers schrieb: > Gregory Petrosyan a écrit : >> I am currently seeking for pythonic alternative for XML. > > A pretty obvious one is dicts and lists. What about (Q&D): > > window = { > 'title' : 'Hello World!' > 'image' : {'text' :"nice picture here", > ... I think this is pretty much the approach of PythonCard (http://pythoncard.sf.net) with its resource files. Bruno, before writing another simple GUI, have a look at PythonCard. Maybe it already does what you want. -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Pythonic gui format?
Christoph Zwerschke wrote: > Bruno Desthuilliers schrieb: > >> Gregory Petrosyan a écrit : >> >>> I am currently seeking for pythonic alternative for XML. >> >> (snip) > Bruno, before writing another simple GUI, Sorry, Christoph, wrong attribution !-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a string
> re.split("(?i)\s*(and not|and|or)\s*", s) Thanks, Frederik for the step by step howto! And also thanks to you, Dylan. re.split("(?i)\s*(and not|and|or)\s*", s) is almost right. I changed it to: words = re.split("(?i)\s*( and not | and | or )\s*", s) in order to handle words containing "or" or "and". s = 'More, J. or Black and Mand, R.' works now, too. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: file names longer than MAX_PATH under Windows 2003
On Tue, 14 Feb 2006 14:29:44 +0300, Sergey wrote: > Hello. > > I try to open file with pathname length 282 bytes: > E:\files\..\something.dat > > On MSDN > (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp) > described method to access > files with path length > up to 32000 bytes: just add prefix \\?\ to file name. > But when I try to pass prefixed name to file(), I get the same result as when > I don't add the prefix: file not found. May be Python > just doesn't support long unicode filenames? > Is there way to open such files? Backslashes have special meaning to Python and need to be escaped. If you do this: f = file("E:\files\...\something.dat", "r") Python's string escape rules means you are actually trying to open the file "E:files...something.dat" which doesn't exist. You should escape the backslashes: f = file("E:\\files\\...\\something.dat", "r") or use raw strings: f = file(r"E:\files\...\something.dat", "r") or just use forward slashes and let Windows deal with it: f = file("E:/files/.../something.dat", "r") Does this help? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of getattr(obj, __dict__)
On Tue, 14 Feb 2006 04:11:52 -0800, Raymond Hettinger wrote: > Steven D'Aprano wrote: >> I came across this unexpected behaviour of getattr for new style classes. >> Example: >> >> >>> class Parrot(object): >> ... thing = [1,2,3] >> ... >> >>> getattr(Parrot, "thing") is Parrot.thing >> True >> >>> getattr(Parrot, "__dict__") is Parrot.__dict__ >> False >> >> I would have expected that the object returned by getattr would be the >> same object as the object returned by standard attribute access. > > The returned object is a wrapper created on-the-fly as needed. You've > requested two of them and each wrapper has a different object id but > wraps an identical source. [penny drops] That would certainly explain it. Is there a canonical list of attributes which are wrapped in this way? I suppose not... it is probably the sort of thing which is subject to change as Python evolves. I knew methods were wrapped, but I didn't know they were wrapped on the fly, nor did I connect the two phenomena. Thank you for the concise and simple answer. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of getattr(obj, __dict__)
Raymond Hettinger wrote: > Steven D'Aprano wrote: > > I came across this unexpected behaviour of getattr for new style classes. > > Example: > > > > >>> class Parrot(object): > > ... thing = [1,2,3] > > ... > > >>> getattr(Parrot, "thing") is Parrot.thing > > True > > >>> getattr(Parrot, "__dict__") is Parrot.__dict__ > > False > > > > I would have expected that the object returned by getattr would be the > > same object as the object returned by standard attribute access. > > The returned object is a wrapper created on-the-fly as needed. You've > requested two of them and each wrapper has a different object id but > wraps an identical source. > > Contemplate this for a bit: > > >>> class Parrot(object): > thing = [1,2,3] > def f(self): pass > > >>> getattr(Parrot, 'f') is getattr(Parrot, 'f') > False > >>> getattr(Parrot, '__dict__') is getattr(Parrot, '__dict__') > False Yes, in fact getattr has nothing to do with it. To wit: >>> Parrot.f is Parrot.f False >>> Parrot.__dict__ is Parrot.__dict__ False But wait, it gets weirder. >>> id(Parrot.f) == id(Parrot.f) True >>> id(Parrot.__dict__) == id(Parrot.__dict__) True But that's not all. Redefine Parrot as: class Parrot(object): def f(self): pass def g(self): pass Then, >>> id(Parrot.f) == id(Parrot.g) True your-milage-may-vary-ly yr's, Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: file names longer than MAX_PATH under Windows 2003
"Tim Golden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] [Sergey] >Not to state the obvious, but can you cut-and-paste that long >string (the one starting with \\?\e:\...) from the Python >interpreter into the [S]tart [R]un [O]pen field to see what >comes up? I'm just trying to make sure of the most straightforward >fact: that the file you've got there definitely does exist! Sorry, it was my error - there was extra backslash in the middle of path. \\?\path works OK. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of getattr(obj, __dict__)
Steven D'Aprano wrote: > >class Parrot(object): > >> > >> ... thing = [1,2,3] > >> ... > >> > >getattr(Parrot, "thing") is Parrot.thing > >> > >> True > >> > >getattr(Parrot, "__dict__") is Parrot.__dict__ > >> > >> False > > > > > > hint: > getattr(object, '__dict__') > > > > That doesn't answer the question, it just re-words it. Why is the > dictproxy returned by getattr a different instance from the dictproxy > that you get when you say object.__dict__? because it's created on the fly: >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ >>> Parrot.__dict__ the object itself contains a dictionary. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
[EMAIL PROTECTED] schrieb: > Then we went to hear Guido speak about Python 2.2 at a ZPUG meeting in > Washington, DC. When he said toople I almost fell out of my chair > laughing, particularly because the people who taught me to say it the > "right" way were with me. When I looked over, they just hung their > head in shame. "Although that way may not be obvious at first unless you're Dutch." ;-) (or German) -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of getattr(obj, __dict__)
On Tue, 14 Feb 2006 13:03:17 +0100, bruno at modulix wrote: > Steven D'Aprano wrote: >> I came across this unexpected behaviour of getattr for new style classes. >> Example: >> >> >class Parrot(object): >> >> ... thing = [1,2,3] >> ... >> >getattr(Parrot, "thing") is Parrot.thing >> >> True >> >getattr(Parrot, "__dict__") is Parrot.__dict__ >> >> False > > > hint: getattr(object, '__dict__') > That doesn't answer the question, it just re-words it. Why is the dictproxy returned by getattr a different instance from the dictproxy that you get when you say object.__dict__? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic gui format?
> > Isn't it ugly a bit? >I'd even say 'ugly 16-bits' !-) You are right of course. Those "examples" are really bad, and, most of all, really un-pythonic. Thanks for JSON. It's more clean&simple than XML, but my main idea is to remove any extra layer between Python and GUI. I want all GUI elements/data to be directly accessible from Python (without extra libraries). Your dicts example is nice, but this approach (and some others) lacks one important feature: ordering of GUI elements. In XML, the order of all elements is specified, and with dicts (or with very clean Georg's model) it is not. (BTW remember topics about ordered dicts...) I think that there should be a way for solving this problem, and I'll certainly try to find it. Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list
Re: python-ldap
On 13 Feb 2006 11:11:05 -0800, rumours say that "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> might have written: >hy... >if you dont know how to help people here... dont say "google it". I never said "google it". I presume you mean this post as a reply to all other posters in this thread, right? And you can bet your tiny _)_ that Steve Holden does know how to help people here, something that can be proven if you google for previous posts of him. >groups.google was made to help! not to say google it! groups.google was made to *archive* newsgroups. By using groups.google, you just participate in the larger community of Usenet. Google that strange term "usenet". It's kind of public email. You send to a "newsgroup", then everybody in the world can see your message, and anybody can reply, and so forth. You'll see in one of the top hits (for "usenet") that Google sometime acquired the Usenet Archive of Deja (Deja.com, DejaNews.com etc), which are archives of newsgroups since before Google existed. There is no company "google.groups" full of professionals getting paid to answer your questions. Think of groups.google as an agency that allows you to travel in the dangerous world of Usenet. >i really dont not what kind of professional you are to say "google it!" Assuming you reply to Steve Holden; you have false logic. Like I said, nobody ever gets paid for replying to newsgroup posts, so professionalism does not get involved in any sense. Or have you sent any money to the PSF [Python Software Foundation] asking for support? If that is the case, I fully apologize, and please don't read the rest of my post! ;) >you are smart boy! I used to be before I grew up. >i think your mom has much pride of you! Especially since she will shortly be a grand mother. >google it to learn more than say "google it!" Your writing style hints you are 14-15 yrs old, but you can also be some non-native English speaker (as I am), even an IT professional (the topic of LDAP does not concern the average adolescent :); in either case, perhaps you might be able and not entirely bored to read more than a few pages: http://www.catb.org/~esr/faqs/smart-questions.html Let this be your guide in your travels in Usenet. Show you did your "homework" before asking others. You see, imagine yourself after about 15-20 years of using computers and discussing them with others (in private or on the internet), and new people keep coming all the time asking the same questions that have been discussed, answered and beaten to death dozens of times before. Steve's using computers for longer than that, and he bothered at least to tell you the obvious step you didn't take: to google your question so you find the previous related discussions. You should thank him for offering his time, because his reply was helpful even if you don't understand it; he directed you to the whereabouts of the answer to your question. Ask groups.google about group:comp.lang.python ldap and work your way from there. When you come back here after you've grokked the "Smart Questions" document, I (and Steve I am sure, and lots of others who didn't bother to reply as Steve did) will be more than glad to help you further your knowledge of Python. Cheers, btaranto. -- TZOTZIOY, I speak England very best. "Dear Paul, please stop spamming us." The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: Cygwin IDLE has no menu bar
* Steve Holden (2006-02-14 04:14 +0100) > I just wondered whether anyone has seen this problem and fixed it. An > IDLE with no menu bar isn't much use ... It's not fixed but the workaround is "idle -n" -- http://mail.python.org/mailman/listinfo/python-list
RE: file names longer than MAX_PATH under Windows 2003
[Sergey] | "Tim Golden" <[EMAIL PROTECTED]> wrote in | message news:[EMAIL PROTECTED] | [Sergey] | | >Not to state the obvious, but can you cut-and-paste that long | >string (the one starting with \\?\e:\...) from the Python | >interpreter into the [S]tart [R]un [O]pen field to see what | >comes up? I'm just trying to make sure of the most straightforward | >fact: that the file you've got there definitely does exist! | | I cannot do this: when I paste filename there, trail of | filename is missing due to length limit in input line. | But I strongly suppose that file exists as its name was get | through os.listdir. I see from another post that CreateFile cannot open your file. That puts it further away from Python, although it doesn't explain how some other program can see the files. Can you use os.startfile (or its equivalent win32api.ShellExecute from pywin32)? Perhaps if you were to chdir to the directory in question you'd be able to access the file. Don't know really; clutching at straws. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Helpful replies (was Re: python-ldap)
On Tue, 07 Feb 2006 12:36:11 -0500, rumours say that Steve Holden <[EMAIL PROTECTED]> might have written: >[EMAIL PROTECTED] wrote: >> y0! >> >> >> >> tks! >gOOgl3, man > >PS: We tend to speak English here :-) Actually, we tend to speak whatever language the OP's experience suggests. I remember the other day, some Humphrey Bogart asked "Are there any waters in Casablanca?" and some smart-_)_ replied "You know how to google, don't ya honey? You just put the little words together and... click search." I ain't sure if Bogey eventually looked it up. -- TZOTZIOY, I speak England very best. "Dear Paul, please stop spamming us." The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: listing attributes
Thanks a lot for all your answers ! Thanks to you I resolved this problem. Here is what i've done : [...] for (_,v) in getmembers(self): if isinstance(v,Property): st += "\t%s\n" % str(v) [...] as all the attributes I want to get are instances of Property or a subclass of Property, it does the trick. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic gui format?
bruno at modulix wrote: > DH wrote: >> Bruno Desthuilliers wrote: >> I am currently seeking for pythonic alternative for XML. >>> >>> A pretty obvious one is dicts and lists. What about (Q&D): >> >> That's like JSON: http://www.json.org/example.html > > No, it's pure Python. It happens that JSON looks pretty close to Python, > but that's another point. Python dict and lists ARE JSON. The only difference that python can't handle is multiline comments. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic gui format?
Gregory Petrosyan wrote: > Thanks for JSON. It's more clean&simple than XML, but my main idea is > to remove any extra layer between Python and GUI. I want all GUI > elements/data to be directly accessible from Python (without extra > libraries). Since JSON is just python dicts and lists, you don't need an extra library to use it, essentially. > Your dicts example is nice, but this approach (and some others) lacks > one important feature: ordering of GUI elements. In XML, the order of > all elements is specified, and with dicts (or with very clean Georg's > model) it is not. (BTW remember topics about ordered dicts...) That's a good point. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic gui format?
DH wrote: > bruno at modulix wrote: > >> DH wrote: >> >>> Bruno Desthuilliers wrote: >>> > I am currently seeking for pythonic alternative for XML. A pretty obvious one is dicts and lists. What about (Q&D): >>> >>> >>> That's like JSON: http://www.json.org/example.html >> >> >> No, it's pure Python. It happens that JSON looks pretty close to Python, >> but that's another point. > > > Python dict and lists ARE JSON. The only difference that python can't > handle is multiline comments. And what about true vs True and false vs False ?-) No, Python's dicts and lists are not JSON. They are Python's dicts and lists. JSON stands for JavaScript Object Notation, and AFAIK, Python and javascript are two different languages (even if they are pretty close on some points). -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: hard disk activity
Terry, Yeah, I was sketching out a scenario much like that. It does break things down pretty well, and that gets my file sync scenario up to much larger files. Even if many changes are made to a file, if you keep track of the number of bytes and checksum over from 1 to the number of bytes different by shifting the sequence ( that is [abcd]ef, a[bced]f, ab[cdef]), until a checksum is a match again, you should be able to find some point where the checksums match again and you can continue up (or down) doing only the checksums again without all the overhead. The question in my mind that I will have to test is how much overhead this causes. One of the business rules underlying this task is to work with files that are being continuously written to, say by logging systems or database servers. This brings with it some obvious problems of file access, but even in cases where you don't have file access issues, I am very concerned about race conditions where one of the already-handled blocks of data are written to. The synched copy on the remote system now no longer represents a true image of the local file. This is one of the reasons I was looking into a device-level solution that would let me know when a hard disk write had occurred. One colleagues suggested I was going to have to write assembler to do this, and I may have to ultimately just use the solutions described here for files that don't have locking and race-condition issues. Regardless, it's a fun project, and I have to say this list is one of the more polite lists I've been involved with. Thanks! V -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic gui format?
DH wrote: > Gregory Petrosyan wrote: > >> Thanks for JSON. It's more clean&simple than XML, but my main idea is >> to remove any extra layer between Python and GUI. I want all GUI >> elements/data to be directly accessible from Python (without extra >> libraries). > > Since JSON is just python dicts and lists, you don't need an extra > library to use it, essentially. Please stop with this nonsense. Python is Python, JSON is Javascript Object Notation, and even if the mapping is quite straightforward, you just can't substitute one for the other. BTW, there *are* some Python<->JSON Python packages... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: 88k regex = RuntimeError
This is basically the same idea as what I tried to describe in my previous post but without any samples. I wonder if it's more efficient to create a new list using a list-comprehension, and checking each entry against the 'wanted' set, or to create a new set which is the intersection of set 'wanted' and the iterable of all matches... Your sample code would then look like this: >>> import re >>> r = re.compile(r"\w+") >>> file_content = "foo bar-baz ignored foo()" >>> wanted = set(["foo", "bar", "baz"]) >>> found = wanted.intersection(name for name in r.findall(file_content)) >>> print found set(['baz', 'foo', 'bar']) >>> Anyone who has an idea what is faster? (This dataset is so limited that it doesn't make sense to do any performance-tests with it) Cheers, --Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3000 deat !? Is true division ever coming ?
[EMAIL PROTECTED] wrote: > Hi, > Is it true that that "Python 3000" is dead ? > Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would > just break to much code :-( > On the otherhand I'm using Python as "Matlab replacement" and would > generally like 5/2 ==2.5 > >... It's Comp. Sci. 101, based on third grade artithmetic, not Python. 5/2=2 is integer division, that's the way integer arithmetic works. 5./2.=2.5 is floating point math, with all the round off errors that incorporates. If Matlab assumes floating point, then that's what you're paying the big bucks for. Curtis -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
Just a few comments... Database: As with anything else, try to keep it simple until you need to make it complex. Sqlite is the simplier alternative, and it's also the fastest for the intended use (small number of users, simple selects, etc). MySQL is also a very good alternative and much more powerful. Mod_python: Mod_python is the best choice (AFAIK, please correct me if I'm wrong) if you want speed, performance and scalability. Many frameworks are based on mod_python (Django, for example), so you can't go wrong with it. But let me tell you that if you just want to use bare-bones mod_python, without any framework on top of it, you can do it, and it's not difficult at all. Mod_python comes with its own implementation of PSP (python server pages), which lets you program a la PHP (intermingling python and html). If you want, you can also separate logic and presentation by using its "publisher handle" along with PSP templates. If you prefer other kinds of templetaing system, you can use them too (for example Cheetah). For a long time I steered away of mod_python because I had the impression it was too difficult and not user friendly enough, what once I tried and followed the examples in the documentation, I found it to be a very good alternative. And the community on its mailing list is very kind and supportive. They reply any question in a matter of minutes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic gui format?
Gregory Petrosyan wrote: >>>Isn't it ugly a bit? >> >>I'd even say 'ugly 16-bits' !-) > > > You are right of course. Those "examples" are really bad, and, most > of all, really un-pythonic. > > Thanks for JSON. It's more clean&simple than XML, but my main idea is > to remove any extra layer between Python and GUI. I want all GUI > elements/data to be directly accessible from Python (without extra > libraries). > Your dicts example is nice, but this approach (and some others) lacks > one important feature: ordering of GUI elements. In XML, the order of > all elements is specified, and with dicts (or with very clean Georg's > model) it is not. (BTW remember topics about ordered dicts...) One possible (but somewhat ugly) solution is to use a list of tuples instead of a dict: d = {'k1': 'v1', 'k2': 'v2'} => l = [('k1', 'v1'), ('k2', 'v2')] where 'values' can of course be any Python data type... Another solution is to include ordering infos in the dict, either as 1/an entry for each item or as 2/a separate entry: 1/ window = { "item" : {'k1': 'v1', 'k2': 'v2', 'order': XXX}, "otheritem" : {'k1n': 'v1n', 'k2n': 'v2n', 'order': YYY}, } 2/ window = { "item" : {'k1': 'v1', 'k2': 'v2'}, "otheritem" : {'k1n': 'v1n', 'k2n': 'v2n'}, "order" : ['item', 'otheritem'], } NB : I'd rather choose the second solution... And finally, you could write your own ordered mapping type - but then you loose the builtin syntax... My 2 (unordered) cents... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: listing attributes
Steven D'Aprano wrote: > On Mon, 13 Feb 2006 22:18:56 -0500, Peter Hansen wrote: >>Thomas Girod wrote: >>>I'm trying to get a list of attributes from a class. The dir() function >>>seems to be convenient, but unfortunately it lists to much - i don't >>>need the methods, neither the built-in variables. >>> >>>In fact, all my variables are referencing to objects of the same type. >>>Can anyone suggest me a way to get this list of variables ? >> >>Does the __dict__ attribute help you? (Try viewing obj.__dict__ at the >>interpreter prompt and see if it has what you expect. >>obj.__dict__.keys() would be just the names of those attributes.) > Parrot.__dict__.keys() > > ['__module__', 'ATTR', 'method', '__dict__', '__weakref__', '__doc__'] > > So I guess the answer to that question is, while __dict__ gives less > information than dir, it still gives too much. I was making the perhaps mistaken assumption that the OP was another of those who meant "object" when he said "class" (though I could perhaps have asked that explicitly). If that were the case, I think __dict__ could be what he wanted. (I'm still not sure what he wanted, even after reading his response, since I can't see what his classes or objects look like...) >>> class Parrot(object): ... ATTR = None ... def method(self): ... return None ... >>> polly = Parrot() >>> polly.foo = '1' >>> polly.bar = 'baz' >>> polly.__dict__ {'foo': '1', 'bar': 'baz'} -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's Edu Corner: accountability & lying thru the teeth
On Tue, 14 Feb 2006 10:33:49 +0100, Xah Lee <[EMAIL PROTECTED]> wrote: > i longed for such a accountable predictions for a long time. Usually, > some fucking fart will do predictions, but the problem is that it's not > accountable. So, lots fuckhead morons in the IT industry will shout > ... Fine, I will hold you accountable for what you said abot IT security two weeks ago. Let's see 'By switching from C to a high level language like Lisp all security problems go away, it's that simple.' Look up 'insertion attack' Then eat SOAP. lol -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / Apache / MySQL
Kalle Anke wrote: > On Tue, 14 Feb 2006 12:04:45 +0100, Peter Hansen wrote: >>Don't optimize prematurely? If you use something like SQLObject, or any >>other means of abstracting yourself away from the details of a specific >>datbase, you won't be particularly tied to it if you decide you need >>improved performance, or sophistication, or whatever. > > That's true ... I was thinking in general terms here (a couple of people I > know handles huge data sets, genome data type of things, and in their case > speed is very important) There is information about SQLite speed starting here http://www.sqlite.org/speed.html (where it notes that that particular page is obsolete, but also points to the wiki for more). The summary would appear to be that SQLite is definitely faster in some cases, definitely slower in others, and that as usual a measurement of inadequate speed followed by profiling is essential to knowing what to do about any of that. :-) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python very slow compared to C
In article <[EMAIL PROTECTED]>, Alex Martelli <[EMAIL PROTECTED]> wrote: . . . >Javascript has leveraged its early advantage in the Netscape browser to >become the only "universally available" language for client-side "in the >browser" execution, and thus established a foothold in a strong and >growing niche for prototype based, rather than class based, object >models. However, there doesn't appear to be further spreading of such >object models; "big" new languages like C# (and indeed the whole >underlying CLR framework, which also forced the semantics of VB) are >strongly class-based. > > >Alex Were we to deepen this analysis, the next aspect to examine is that, in my estimation, the JavaScript user community is unusual in the extent to which its users don't aspire to comprehensive understanding. Say to a Java or Eiffel or Lua programmer, "You didn't know about {inner definitions|nested dictionaries|...}," and my bet is he'll say, "Tell me more." Tell the majority of JS users that they don't seem to be aware of inheritance constructs, and they respond, "So?" That's a crude generalization, but one I think useful. If true, it helps explain the comparative lack of penetration of prototype-based object orientation. -- http://mail.python.org/mailman/listinfo/python-list
Embedding an Application in a Web browser
Is it possible to embed a Python application within Internet explorer? If so how do people recommend going about it. As for the application it has to be able display simple animated graphics such as circles, lines and squares. However if someone clicks on a shape it should open up another application, such as Word. Thanks, Rod Python Newbie -- http://mail.python.org/mailman/listinfo/python-list
Re: 88k regex = RuntimeError
Tim N. van der Leeuw wrote: > This is basically the same idea as what I tried to describe in my > previous post but without any samples. > I wonder if it's more efficient to create a new list using a > list-comprehension, and checking each entry against the 'wanted' set, > or to create a new set which is the intersection of set 'wanted' and > the iterable of all matches... > > Your sample code would then look like this: > import re r = re.compile(r"\w+") file_content = "foo bar-baz ignored foo()" wanted = set(["foo", "bar", "baz"]) found = wanted.intersection(name for name in r.findall(file_content)) Just found = wanted.intersection(r.findall(file_content)) print found > set(['baz', 'foo', 'bar']) > > Anyone who has an idea what is faster? (This dataset is so limited that > it doesn't make sense to do any performance-tests with it) I guess that your approach would be a bit faster though most of the time will be spent on IO anyway. The result would be slightly different, and again yours (without duplicates) seems more useful. However, I'm not sure whether the OP would rather stop at the first match or need a match object and not just the text. In that case: matches = (m for m in r.finditer(file_content) if m.group(0) in wanted) Peter -- http://mail.python.org/mailman/listinfo/python-list
Embedding an Application in a Web browser
> Is it possible to embed a Python application within Internet explorer? > If so how do people recommend going about it. > > As for the application it has to be able display simple animated > graphics such as circles, lines and squares. However if someone clicks > on a shape it should open up another application, such as Word. > > Thanks, > > Rod > > Python Newbie Do you mean perhaps embedding python into a webserver? If you want to use apache as your server that is possible, check the mod_python module which embeds the python interpreter into apache. You can then write your application in python (displaying your animated graphics, etc) and visitors to your server will see what you the output from your program. For further info: http://modpython.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Rethinking the Python tutorial
A.M. Kuchling wrote: > On Mon, 13 Feb 2006 11:03:55 -0500, > Steve Holden <[EMAIL PROTECTED]> wrote: >>What we are talking about here is a Python Language Users' Guide. > > I actually started on such a document over the holidays, but have only > described about 3 or 4 statements at this point. Great! I hope you'll find the time to make this into something useful. I don't know how easy it is to make such a thing into a collaborative effort. Either way, I think some kind of champion is needed... I hope we'll see some kind of tools for on-line collaboration for python.org soon, whether it's something wiki-like or some other way to add comments to the web pages. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
[EMAIL PROTECTED] > ... > I work with Guido now and I'm conflicted. I'm still conditioned to say > tuhple. Whenever he says toople, I just get a smile on my face. I > think most of the PythonLabs guys pronounce it toople. "tuhple" is a girly-man affectation. That's why Guido and I both say the manly "toople". Jeremy's still a baby, so he says "tuhple", and for the same reasons other adolescent males pierce their nipples. Barry sucks up to whoever he's talking with at the moment. Fred is a doc guy, so nobody remembers what he says ;-) the-acid-test-is-whether-you-say-"xor"-with-one-syllable-or-three-ly y'rs - tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding an Application in a Web browser
Didn't ActiveState or somebody have a Python plugin to run Python on IE? -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
Erik Max Francis wrote: > If a 4-tuple is a quadruple, a 3-tuple is a triple, a > 2-tuple is an pair, then I guess a 1-tuple would be a single. Granted > that's not nearly as gruesome enough a name to go with the special > lopsided Pythonic creature mentioned above. I suggest we name it a > hurgledink. +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
Tim Peters <[EMAIL PROTECTED]> wrote: > the-acid-test-is-whether-you-say-"xor"-with-one-syllable-or-three-ly y'rs I pronounce it with two. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding an Application in a Web browser
'A' Web Browser? Meaning: any random web-browser? Or specifically and *only* Internet Explorer? If you want it to work only and ever only in Internet Explorer, then you can create a Python ActiveX object and embed that in your page; using the pythonwin extensions. Cheers, --Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding an Application in a Web browser
Perhaps IronPython could be hacked in somehow also? Seems like it might could. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding an Application in a Web browser
Perhaps IronPython could be hacked in somehow also? Seems like it might could. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3000 deat !? Is true division ever coming ?
On 14 Feb 2006 06:44:02 -0800, [EMAIL PROTECTED] > 5./2.=2.5 is floating point math, with all the round off errors that > incorporates. Thanks Curtis, I never knew that trick. I guess for variables do have true division you have to make them floats? e.g. float(var1)/float(var2)? Or do you know a less typing approach for that? -- Gregory Piñero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding an Application in a Web browser
rodmc wrote: > Is it possible to embed a Python application within Internet explorer? No. Nor in any other browser (except from Grail, but I think this doesn't count). > If so how do people recommend going about it. Either write a rich client app or a real web application. > As for the application it has to be able display simple animated > graphics such as circles, lines and squares. Wait... Aren't there already existing technos to do this ? > However if someone clicks > on a shape it should open up another application, such as Word. Lol. This would be a really big bad security issue. You definitively want to write a rich client app. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
Tim Peters wrote: > "tuhple" is a girly-man affectation. That's why Guido and I both say > the manly "toople". Heh heh. Actually, 'toople' sounds like a noun to me, and 'tuple' sounds like a verb, so I prefer 'toople' anyway. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce 'tuple'?
::snip a thousand responses:: Well, I'm certainly glad I brought it up. :) -- http://mail.python.org/mailman/listinfo/python-list