Re: Using Regular Expressions to Parse SQL

2008-02-05 Thread MRAB
On Feb 5, 6:18 pm, [EMAIL PROTECTED] wrote: Firstly, thanks to those who posted. I just do not understand how the non-greedy operator works. Using the following code: import re s = qry_Lookup.desc = CSS_Rpt1.desc AND qry_Lookup.lcdu1 = CSS_Rpt1.lcdu pat = (.+=)+?(.+) ^^

Re: packing things back to regular expression

2008-02-21 Thread MRAB
On Feb 20, 7:36 pm, Amit Gupta [EMAIL PROTECTED] wrote: Before I read the message: I screwed up. Let me write again x = re.compile(CL(?Pname1[a-z]+)) # group name name1 is attached to the match of lowercase string of alphabet # Now I have a dictionary saying {name1, iamgood} # I would

Re: Handling global variables (Newbie)

2008-03-14 Thread MRAB
On Mar 13, 4:25 am, David S [EMAIL PROTECTED] wrote: Hi, I have an error occurring at self.build_root = os.path.abspath(os.path.split(__file__)[0]) The error states 'NameError: global name '__file__' is not defined' In Python 2.5 I ran my script as a module in IDLE gui. How does

Re: os.path.isdir question

2008-03-16 Thread MRAB
On Mar 16, 2:27 am, Benjamin [EMAIL PROTECTED] wrote: On Mar 15, 8:12 pm, lampshade [EMAIL PROTECTED] wrote: Hello, I'm having some problems with os.path.isdir I think it is something simple that I'm overlooking. #!/usr/bin/python import os my_path = os.path.expanduser(~/pictures/)

Re: Trouble with variable leakage?

2008-03-20 Thread MRAB
On Mar 21, 3:05 am, Jeremy N [EMAIL PROTECTED] wrote: I am working with Python in Maya, and have run into a problem with a variable changing its contents without being scripted to do so. The various print() statements below were from my efforts to track down where it was occurring. I left them

Re: Is this doable

2008-03-21 Thread MRAB
On Mar 21, 11:48 am, fkallgren [EMAIL PROTECTED] wrote: Hi. I have a little problem. I have a script that is in the scheduler (win32). But every now and then I update this script and I dont want to go to every computer and update it. So now I want the program to 1) check for new version of

Re: Why prefer != over for Python 3.0?

2008-03-30 Thread MRAB
On Mar 30, 6:35 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 30 Mar 2008 02:11:33 -0300, hdante [EMAIL PROTECTED] escribió: BTW, my opinion is that it's already time that programmer editors have input methods advanced enough for generating this: if x ≠ 0: ∀y ∈ s:

Re: Why prefer != over for Python 3.0?

2008-04-01 Thread MRAB
On Mar 30, 7:59 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 30 Mar 2008 11:10:20 -0300, MRAB [EMAIL PROTECTED] escribió: On Mar 30, 6:35 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 30 Mar 2008 02:11:33 -0300, hdante [EMAIL PROTECTED] escribió: BTW, my opinion

Re: non-terminating regex match

2008-04-02 Thread MRAB
On Apr 2, 5:01 pm, Maurizio Vitale [EMAIL PROTECTED] wrote: Has to be something really stupid, but the following never finish (running Python 2.5.1 (r251:54863, Jan 10 2008, 18:00:49) [GCC 4.2.1 (SUSE Linux)] on linux2). The intention is to match C++ identifiers, with or without namespace

Re: I just killed GIL!!!

2008-04-17 Thread MRAB
On Apr 17, 5:22 am, Torsten Bronger [EMAIL PROTECTED] wrote: Hallöchen! Tim Daneliuk writes: Daniel Fetchinson wrote: [...] I just had one moment of exceptional clarity, during which realized how I could get the GIL out of my way... It's so simple, I cannot help wondering why nobody

Re: Profiling, recursive func slower than imperative, normal?

2008-04-17 Thread MRAB
On Apr 17, 9:39 am, Robert Bossy [EMAIL PROTECTED] wrote: Gabriel Genellina wrote: En Wed, 16 Apr 2008 17:53:16 -0300, [EMAIL PROTECTED] escribió: On Apr 16, 3:27 pm, Jean-Paul Calderone [EMAIL PROTECTED] wrote: Any function can be implemented without recursion, although it isn't always

Re: Problems replacing \ with \\

2008-04-21 Thread MRAB
On Apr 21, 11:48 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi... Here's a weird problem...I'm trying to escape a bunch of data to put into a database. Here's what I have: def escape(string): Escape both single quotes and blackslashes x = rfun\fun escape(x)

Re: Code/test ratio wrt static vs dynamic typing [was: Re: Python Success stories]

2008-04-30 Thread MRAB
On Apr 30, 10:47 am, [EMAIL PROTECTED] wrote: A rather off-topic and perhaps naive question, but isn't a 1:4 production/test ratio a bit too much ? Is there a guesstimate of what percentage of this test code tests for things that you would get for free in a statically typed language ? I'm

Re: slicing lists

2008-05-08 Thread MRAB
On May 8, 4:34 am, Yves Dorfsman [EMAIL PROTECTED] wrote: Miles wrote: On Wed, May 7, 2008 at 7:46 PM, Ivan Illarionov Is there a way to do: x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] x[0,2:6] That would return: [0, 3, 4, 5, 6] Arg... Yes, this is a typo, I meant: [1,

Re: How can I add spaces where ever I have capital letters?

2008-05-09 Thread MRAB
On May 9, 3:04 am, Eric Wertman [EMAIL PROTECTED] wrote: Something like this. I'm sure there are other ways to do it. import re def addspace(m) : return ' ' + m.group(0) strng = ModeCommand newstr = re.sub('[A-Z]',addspace,strng) Alternatively: newstr = re.sub('([A-Z])',r'

Re: Python doesn't recognize quote types

2008-05-12 Thread MRAB
On May 12, 8:31 am, Duncan Booth [EMAIL PROTECTED] wrote: Dennis Lee Bieber [EMAIL PROTECTED] wrote: The sloppy use of single quote for the apostrophe is unfortunate G True, but that problem is outside of the Python community's control. Given that people do often refer to single quote

Re: Python and Flaming Thunder

2008-05-13 Thread MRAB
On May 13, 6:32 pm, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote: On Tue, 13 May 2008 19:57:10 +0300 Andrii V. Mishkovskyi [EMAIL PROTECTED] wrote: Not everybody has grown in English-speaking community, you know. And knowing math quite good, I prefer writing x = y instead of Set x to y.

Re: Python and Flaming Thunder

2008-05-14 Thread MRAB
On May 14, 10:30 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Dave Parker schrieb: All of the calculators and textbooks that elementary school students use, use ^ for powers. I've never seen this symbol in textbooks. In textbooks, powers are written using superscript. Just like

Re: no inputstream?

2008-05-15 Thread MRAB
On May 15, 9:00 pm, max [EMAIL PROTECTED] wrote: you're right, my java implementation does indeed parse for Id3v2 (sorry for the confusion). i'm using the getrawid3v2() method of this bitstream class (http://www.javazoom.net/javalayer/docs/docs0.4/ javazoom/jl/decoder/Bitstream.html) to

Re: can't delete from a dictionary in a loop

2008-05-16 Thread MRAB
On May 16, 10:22 pm, Dan Upton [EMAIL PROTECTED] wrote: This might be more information than necessary, but it's the best way I can think of to describe the question without being too vague. The task: I have a list of processes (well, strings to execute said processes) and I want to,

Re: unescape escapes in strings

2009-02-23 Thread MRAB
bvdp wrote: When reading lines of data from a file in the from (no quotes!) foo\x20bar and I assign to a variable in a line line like: f = file('infile', 'r') for a in f: print a the string is read in as string with the literal characters 'f', 'o' ... 'x' , '2' ... as compared

Re: unescape escapes in strings

2009-02-23 Thread MRAB
bvdp wrote: MRAB wrote: bvdp wrote: When reading lines of data from a file in the from (no quotes!) foo\x20bar and I assign to a variable in a line line like: f = file('infile', 'r') for a in f: print a the string is read in as string with the literal characters 'f', 'o' ... 'x

Re: more on unescaping escapes

2009-02-23 Thread MRAB
bvdp wrote: So, we think something is working and send of a bug fix to our client :) I'm not sure I understand this at all and wonder if there is bug? a=c:\\Program\x20Files\\test a 'c:\\Program Files\\test' so far, so good. a.decode(string-escape) 'c:\\Program Files\test' Umm, not

Re: read csv error question

2009-02-23 Thread MRAB
Vincent Davis wrote: I am trying to read a csv file from excel on a mac. I get the following error. SystemExit: file some.csv, line 1: new-line character seen in unquoted field - do you need to open the file in universal-newline mode? I was using the example code import csv, sys reader =

Re: read csv error question

2009-02-23 Thread MRAB
Benjamin Kaplan wrote: On Mon, Feb 23, 2009 at 6:43 PM, MRAB goo...@mrabarnett.plus.com mailto:goo...@mrabarnett.plus.com wrote: Vincent Davis wrote: I am trying to read a csv file from excel on a mac. I get the following error. SystemExit: file some.csv, line 1

Re: getting at individual bits inside byte field: struct module : bitwise operator

2009-02-23 Thread MRAB
harijay wrote: In my last post I had asked about reading data from a binary file using the struct module. Thanks to some excellent help , I have managed to read in successfully most of the header of this binary format that I want to parse. These are some time-voltage traces from a digital to

Re: EOL for sys.stdin.readline() and raw_input()

2009-02-26 Thread MRAB
jkv wrote: Hi, Are there any way to change the EOL character for sys.stdin.readline() and raw_input()? My problem is that i cannot rely on that the clients connection to my application will end all lines with \n or \r\n. Sometimes they will use \r\000 as EOL. Example from my code:

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-26 Thread MRAB
Trip Technician wrote: anyone interested in looking at the following problem. we are trying to express numbers as minimal expressions using only the digits one two and three, with conventional arithmetic. so for instance 33 = 2^(3+2)+1 = 3^3+(3*2) are both minimal, using 4 digits but 33 =

Re: struct.unpack() on a stream

2009-02-27 Thread MRAB
Gabriel Genellina wrote: En Fri, 27 Feb 2009 09:29:16 -0200, Ulrich Eckhardt eckha...@satorlaser.com escribió: I have a socket from which I would like to parse some data, how would I do that? Of course, I can manually read data from the socket until unpack() stops complaining about a lack of

Re: Bug report: ClientForm

2009-02-28 Thread MRAB
Muddy Coder wrote: Hi Folks, As directed, I got ClientForm and played with it. It is cool! However, I also found a bug: When it parses a form, if the VALUE of a field has not space, it works very well. For example, if a dropdown list, there many options, such as: option value=foo the

Re: Email Program

2009-02-28 Thread MRAB
J wrote: Is it possible to make a GUI email program in Python that stores emails, composes, ect? Yes. -- http://mail.python.org/mailman/listinfo/python-list

Re: file locking...

2009-03-01 Thread MRAB
bruce wrote: Hi. Got a bit of a question/issue that I'm trying to resolve. I'm asking this of a few groups so bear with me. I'm considering a situation where I have multiple processes running, and each process is going to access a number of files in a dir. Each process accesses a unique group

Re: unziping a file in python..

2009-03-02 Thread MRAB
Steven D'Aprano wrote: On Mon, 02 Mar 2009 01:00:54 -0500, David Lyon wrote: It might seem a simple question.. but how does one programmaticaly unzip a file in python? A quick and dirty solution would be something like this: zf = zipfile.ZipFile('Archive.zip') for name in zf.namelist():

Re: unziping a file in python..

2009-03-02 Thread MRAB
Luis Zarrabeitia wrote: Quoting MRAB goo...@mrabarnett.plus.com: Steven D'Aprano wrote: A quick and dirty solution would be something like this: zf = zipfile.ZipFile('Archive.zip') for name in zf.namelist(): open(name, 'w').write(zf.read(name)) You might want to specify an output folder

Re: How can I add space in to several numbers?

2009-03-02 Thread MRAB
Gabriel Genellina wrote: En Mon, 02 Mar 2009 17:58:01 -0200, Bo Zhang primroseb...@gmail.com escribió: I want to parse a file and do this : A 74.335 -86.474-129.317 1.00 54.12 then add space between -86.474 and -129.317. I can get the file with A 74.335 -86.474 -129.317 1.00

Re: Upgrade Python on a Mac

2009-03-02 Thread MRAB
Rey Bango wrote: Hi, I'd like to upgrade the installed version of Python that came standard on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot in it, I just wanted to get a better understanding of the process. If I download the disk image installer from here:

Re: Pickle Problem

2009-03-03 Thread MRAB
Fab86 wrote: I am getting res1 and res2 etc from this code: srch1 = WebSearch(app_id=YahooKey) srch1.query = avoir site:.al res1 = srch1.parse_results() srch2 = WebSearch(app_id=YahooKey) srch2.query = avoir site:.fr res2 = srch2.parse_results() After identifying res1, I then use the

Re: Perl-python regex-performance comparison

2009-03-03 Thread MRAB
Chris Rebert wrote: On Tue, Mar 3, 2009 at 9:05 AM, Ivan i...@invalid.net wrote: Hello everyone, I know this is not a direct python question, forgive me for that, but maybe some of you will still be able to help me. I've been told that for my application it would be best to learn a scripting

Re: Pickle Problem

2009-03-03 Thread MRAB
Fab86 wrote: On Mar 3, 8:59 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 03 Mar 2009 16:50:25 -0200, Fab86 fabien.h...@gmail.com escribió: On Mar 3, 6:48 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 03 Mar 2009 16:39:43 -0200, Fab86 fabien.h...@gmail.com

Re: Pickle Problem

2009-03-04 Thread MRAB
Fab86 wrote: On Mar 4, 1:40 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 03 Mar 2009 23:11:30 -0200, Fab86 fabien.h...@gmail.com escribió: On Mar 4, 12:00 am, MRAB goo...@mrabarnett.plus.com wrote: Fab86 wrote: On Mar 3, 8:59 pm, Gabriel Genellina gagsl-...@yahoo.com.ar

Re: Parsing/Crawler Questions..

2009-03-04 Thread MRAB
bruce wrote: Hi... Sorry that this is a bit off track. Ok, maybe way off track! But I don't have anyone to bounce this off of.. I'm working on a crawling project, crawling a college website, to extract course/class information. I've built a quick test app in python to crawl the site. I crawl

Re: Reading a file

2009-03-05 Thread MRAB
Aahz wrote: In article mailman.9538.1234633556.3487.python-l...@python.org, Terry Reedy tjre...@udel.edu wrote: for line in open('char.txt'): if line.find('sweet') != -1 or line.find('blue') != -1: print(line) For any recent Python, this should be: if 'sweet' in line or 'blue' in

Re: Pickle Problem

2009-03-05 Thread MRAB
Fab86 wrote: On Mar 4, 2:49 pm, MRAB goo...@mrabarnett.plus.com wrote: Fab86 wrote: On Mar 4, 1:40 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 03 Mar 2009 23:11:30 -0200, Fab86 fabien.h...@gmail.com escribió: On Mar 4, 12:00 am, MRAB goo...@mrabarnett.plus.com wrote: Fab86

Re: Can Python do shopping cart?

2009-03-06 Thread MRAB
Paul Rubin wrote: Tim Wintle tim.win...@teamrubber.com writes: Surely you can address an infinite amount of storage using infinite length integers and a wrapper to files on disk - then it's just your OS's limits that hold it back - so python is turing/register complete. Python doesn't have

Re: ANN: Dao, the official 1.0 version is released

2009-03-07 Thread MRAB
Limin Fu wrote: Dennis Lee Bieber wrote: Whatever it is, the name does tend to lend confusion with the older Microsoft database access method DAO (which was superceded by ADO). I don't think there is confusion here, because the Microsoft database access method DAO is not a programming

Re: Should I use stackless python or threads?

2009-03-07 Thread MRAB
John Nagle wrote: Minesh Patel wrote: On Fri, Mar 6, 2009 at 3:16 PM, Jean-Paul Calderone exar...@divmod.com wrote: On Fri, 6 Mar 2009 14:50:51 -0800, Minesh Patel min...@gmail.com wrote: I am trying to figure out the best approach to solve this problem: I want to poll various

Re: NEWB: dividing numbers

2009-03-08 Thread MRAB
Lo wrote: I just tried python first time. 2/3 the result is zero I want the result to be .333... How do I get this? That's integer division (integer divided by integer is integer). If you want the result to be floating point then make one of them floating point: 2.0 / 3 or do this

Re: Mapping 64 bit int from C to Python-2.2

2009-03-09 Thread MRAB
Explore_Imagination wrote: Hi I want to map 64 bit integers from C to python. I must use Python 2.2 BUT There is no support for 64 bits integers in Python2.2 (Supported in 2.5). Now the problem is that I have these four variables: unit32_t a,b,c; uint64_t w,x,y,z; I use this funtion to map

Re: Eject a Removable USB drive

2009-03-09 Thread MRAB
Rickey, Kyle W wrote: Hello everyone, I would like to be able to eject a usb drive based on drive letter. I've done a bit of googling and came across the CM_Request_Device_Eject function on MSDN (http://msdn.microsoft.com/en-us/library/ms790831.aspx) However, I am not quite sure how

Re: Why is lambda allowed as a key in a dict?

2009-03-09 Thread MRAB
Daniel Fetchinson wrote: Python 2.5.1 (r251:54863, Oct 30 2007, 13:45:26) [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 Type help, copyright, credits or license for more information. x = { } x[lambda arg: arg] = 5 x[lambda arg: arg] Traceback (most recent call last): File stdin, line 1,

Re: calling class methods from class methods, help?

2009-03-11 Thread MRAB
Oltmans wrote: I've a multithreaded program in which I've to call class methods from class methods. Here is how my code look like (excluding imports),. Any help is highly appreciated. #!/usr/bin/env python class Requests(Thread): def __init__(self, times): Thread.__init__(self)

Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-12 Thread MRAB
Raymond Hettinger wrote: [snip] Proposal I (from Nick Coghlan): --- A comma will be added to the format() specifier mini-language: [[fill]align][sign][#][0][minimumwidth][,][.precision][type] The ',' option indicates that commas should be included in the output as

Re: Raw String Question

2009-03-12 Thread MRAB
Jim Garrison wrote: Tim Chase wrote: ra\ SyntaxError: EOL while scanning string literal (pyshell#45, line 1) It seems the parser is interpreting the backslash as an escape character in a raw string if the backslash is the last character. Is this expected? Yep...as documented[1], even a

Re: Raw String Question

2009-03-12 Thread MRAB
andrew cooke wrote: MRAB wrote: [...] The other special case is with \u in a Unicode string: ur\u0041 u'A' this isn't true for 3.0: r\u0041 '\\u0041' (there's no u because it's a string, not a bytes literal) and as far as i can tell, that's correct behaviour according to the docs

Re: Raw String Question

2009-03-13 Thread MRAB
andrew cooke wrote: MRAB wrote: andrew cooke wrote: MRAB wrote: [...] The other special case is with \u in a Unicode string: ur\u0041 u'A' this isn't true for 3.0: r\u0041 '\\u0041' (there's no u because it's a string, not a bytes literal) and as far as i can tell, that's correct

Re: Special keyword argument lambda syntax

2009-03-13 Thread MRAB
Rhodri James wrote: On Fri, 13 Mar 2009 14:49:17 -, Beni Cherniavsky beni.cherniav...@gmail.com wrote: Specification = Allow keyword arguments in function call to take this form: NAME ( ARGUMENTS ) = EXPRESSION which is equivallent to the following: NAME = lambda

Re: An ordering question

2009-03-13 Thread MRAB
Kottiyath wrote: Hi, I have 2 lists a = [(4, 1), (7, 3), (3, 2), (2, 4)] b = [2, 4, 1, 3] Now, I want to order _a_ (a[1]) based on _b_. i.e. the second element in tuple should be the same as b. i.e. Output would be [(3, 2), (2, 4), (4, 1), (7, 3)] I did the same as follows:

Re: Special keyword argument lambda syntax

2009-03-13 Thread MRAB
Hrvoje Niksic wrote: MRAB goo...@mrabarnett.plus.com writes: sorted(range(9), def key(n): n % 3) [0, 3, 6, 1, 4, 7, 2, 5, 8] Given the recent pattern of syntactic constructs for expressions using expr keyword expr (ternary if, listcomps, genexps), and avoiding the use of colon

Re: An ordering question

2009-03-13 Thread MRAB
MRAB wrote: Kottiyath wrote: Hi, I have 2 lists a = [(4, 1), (7, 3), (3, 2), (2, 4)] b = [2, 4, 1, 3] Now, I want to order _a_ (a[1]) based on _b_. i.e. the second element in tuple should be the same as b. i.e. Output would be [(3, 2), (2, 4), (4, 1), (7, 3)] I did

Re: Neatest way to do a case insensitive in?

2009-03-13 Thread MRAB
tinn...@isbd.co.uk wrote: What's the neatest way to do the following in case insensitive fashion:- if stringA in stringB: bla bla bla I know I can just do:- if stringA.lower() in stringB.lower(): bla bla bla But I was wondering if there's a neater/easier way? Not

Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-13 Thread MRAB
Raymond Hettinger wrote: Todays updates to: http://www.python.org/dev/peps/pep-0378/ * Detail issues with the locale module. * Summarize commentary to date. -- Opposition to formatting strings in general (preferring a convenience function or PICTURE clause) -- Opposition to any

Re: Style question - defining immutable class data members

2009-03-14 Thread MRAB
Maxim Khitrov wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object): def __init__(self): self.some_value = 0 self.another_value = None Similar effect

Re: don't understand behaviour of recursive structure

2009-03-14 Thread MRAB
Dan Davison wrote: I'm new to python. Could someone please explain the following behaviour of a recursive data structure? def new_node(id='', daughters=[]): return dict(id=id, daughters=daughters) n0 = new_node(id='n0') n1 = new_node(id='n1') [snip] See

Re: don't understand behaviour of recursive structure

2009-03-14 Thread MRAB
bieff...@gmail.com wrote: On 14 Mar, 17:31, Dan Davison davi...@stats.ox.ac.uk wrote: I'm new to python. Could someone please explain the following behaviour of a recursive data structure? def new_node(id='', daughters=[]): return dict(id=id, daughters=daughters) Most probably, here is

Re: little question speed encondings

2009-03-14 Thread MRAB
Linos wrote: I know that this can be evident for most of the people but i would like to know the reply and the reasoning if possible: Should my python application have a difference in speed of execution after change the encoding header of the file from nothing (ascii) to latin-1 or utf-8? If

Re: how to repeat function definitions less

2009-03-14 Thread MRAB
alex goretoy wrote: I'm doing this in my code, how to make it define all this functions for me with lambda, I've been up for a while and cant seem to figure it out, whats the most efficient way to do it? with lambda? how? thx def red(self,value,color='red',level='INFO'):

Re: how to repeat function definitions less

2009-03-15 Thread MRAB
alex goretoy wrote: I would imagine that I could do this with a generator and setattr, but I am still learning how to do that kinda of codingmaybe if I had a dictionary like this and then loaded it d={ site_name:[s,site,'sites','site_name','site_names'],

Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-15 Thread MRAB
Rhodri James wrote: [snip] Frankly, I'd much rather fix the locale system and extend the format syntax to override the default locale. Perhaps something like financial = Locale(group_sep=,, grouping=[3]) print(my number is {0:10n:financial}.format(1234567)) It's hard to think of a way of

Re: how to repeat function definitions less

2009-03-15 Thread MRAB
alex goretoy wrote: ok now for the final result, i decided to split options out to a separate dict of lists, does this look right to every one, I currently have error somewhere else in my code so can't test this right now, Is this a good method to do this? or is there another option? [snip]

Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-15 Thread MRAB
Rhodri James wrote: On Sun, 15 Mar 2009 19:00:43 -, MRAB goo...@mrabarnett.plus.com wrote: Rhodri James wrote: [snip] Frankly, I'd much rather fix the locale system and extend the format syntax to override the default locale. Perhaps something like financial = Locale(group_sep

Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread MRAB
Rhodri James wrote: On Mon, 16 Mar 2009 02:36:43 -, MRAB goo...@mrabarnett.plus.com wrote: The field name can be an integer or an identifier, so the locale could be too, provided that you know where to look it up! financial = Locale(group_sep=,, grouping=[3]) print(my number

Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread MRAB
Rhodri James wrote: On Mon, 16 Mar 2009 23:04:58 -, MRAB goo...@mrabarnett.plus.com wrote: It should probably(?) be: financial = Locale(group_sep=,, grouping=[3]) print(my number is {0:10n:fin}.format(1234567, fin=financial)) The format 10n says whether to use separators

Re: Run on Startup

2009-03-16 Thread MRAB
Ian Mallett wrote: Hi, I'd like to make a program that automatically runs on startup (right after login). How should I do that? Put it in the folder: C:\Documents and Settings\username\Start Menu\Programs\Startup The exact path depends on your login/username and I'm assuming that Windows

Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread MRAB
Rhodri James wrote: On Tue, 17 Mar 2009 01:47:32 -, MRAB goo...@mrabarnett.plus.com wrote: I'm not against putting a comma in the format to indicate that grouping should be used just as a dot indicates that a decimal point should be used. The locale would say what characters would be used

Re: ValueError: filedescriptor out of range in select()

2009-03-17 Thread MRAB
Laszlo Nagy wrote: Hi Laszlo, Just a hunch -- are you leaking file handles and eventually running out? These file handles are for TCP sockets. They are accept()-ed, used and then thrown out. I guess after the connection was closed, the file handle is destroyed automatically. BTW here is the

Re: How to do this in Python?

2009-03-17 Thread MRAB
Jim Garrison wrote: [snip] Ah. That's the Pythonesque way I was looking for. FYI, the correct word is Pythonic. Pythonesque refers to Monty Python. -- http://mail.python.org/mailman/listinfo/python-list

Re: [python-list] Re: Strange crash issue on Windows w/ PyGTK, Cairo...

2009-03-18 Thread MRAB
CJ Kucera wrote: bieff...@gmail.com wrote: It looks like some of the C extension you are using is causing a segfault or similar in python interpreter (or it could be a bug in the interpreter itself, but it is a lot less likely). Okay... I assume by C extension you'd include the PyGTK stuff,

Re: Tuple passed to function recognised as string

2009-03-18 Thread MRAB
Mike314 wrote: Hello, I have following code: def test_func(val): print type(val) test_func(val=('val1')) test_func(val=('val1', 'val2')) The output is quite different: type 'str' type 'tuple' Why I have string in the first case? It's the comma that makes the tuple, except for one

Re: Can I rely on...

2009-03-19 Thread MRAB
Emanuele D'Arrigo wrote: Hi everybody, I just had a bit of a shiver for something I'm doing often in my code but that might be based on a wrong assumption on my part. Take the following code: pattern = aPattern compiledPatterns = [ ] compiledPatterns.append(re.compile(pattern))

Re: Can I rely on...

2009-03-19 Thread MRAB
Emanuele D'Arrigo wrote: [snip] If the answer is no, am I right to state the in the case portrayed above the only way to be safe is to use the following code instead? for item in compiledPatterns: if(item.pattern == pattern): print(The compiled pattern is stored.) break

Re: converting pipe delimited file to fixed width

2009-03-19 Thread MRAB
digz wrote: Hi, I am trying to convert a | delimited file to fixed width by right padding with spaces, Here is how I have written the program , just get the feeling this can be done in a much better ( python functional ) way rather than the procedural code i have below . Any help appreciated

Re: converting pipe delimited file to fixed width

2009-03-19 Thread MRAB
Terry Reedy wrote: digz wrote: Hi, I am trying to convert a | delimited file to fixed width by right padding with spaces, Here is how I have written the program , just get the feeling this can be done in a much better ( python functional ) way rather than the procedural code i have below . Any

Re: Missing values in tuple assignment

2009-03-19 Thread MRAB
Albert Hopkins wrote: On Thu, 2009-03-19 at 11:57 -0500, Jim Garrison wrote: Use case: parsing a simple config file line where lines start with a keyword and have optional arguments. I want to extract the keyword and then pass the rest of the line to a function to process it. An obvious use of

Re: Parallel processing on shared data structures

2009-03-19 Thread MRAB
psaff...@googlemail.com wrote: I'm filing 160 million data points into a set of bins based on their position. At the moment, this takes just over an hour using interval trees. I would like to parallelise this to take advantage of my quad core machine. I have some experience of Parallel Python,

Re: converting pipe delimited file to fixed width

2009-03-19 Thread MRAB
John Posner wrote: [snip] field_widths = [14, 6, 18, 21, 21, 4, 6] out = open(/home/chatdi/ouptut.csv, 'w') for line in open(/home/chatdi/input.csv, r): fields = line.rstrip().split('|') padded_fields = [field.ljust(width) for field, width in zip(fields, field_widths)]

Re: Heuristically processing documents

2009-03-19 Thread MRAB
BJörn Lindqvist wrote: I have a large set of documents in various text formats. I know that each document contains its authors name, email and phone number. Sometimes it also contains the authors home address. The task is to find out the name, email and phone of as many documents as possible.

Re: Need guidelines to show results of a process

2009-03-19 Thread MRAB
Vizcayno wrote: Hi: I wrote a Python program which, during execution, shows me messages on console indicating at every moment the time and steps being performed so I can have a 'log online' and guess remaining time for termination, I used many 'print' instructions to show those messages, i.e.

Re: locate items in matrix (index of lists of lists)

2009-03-20 Thread MRAB
Chris Rebert wrote: On Fri, Mar 20, 2009 at 4:34 AM, Alessandro Zivelonghi zasaconsult...@gmail.com wrote: Many Thanks guys! and what if I need to look ONLY into the second and third columns, excluding the first item of each rows? for example if x = 3 I need to get [0] and not [0,1]

Re: get rid of duplicate elements in list without set

2009-03-20 Thread MRAB
Tino Wildenhain wrote: thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. That would leave a B with value None :-) B=list(sorted(set(A)) could work. sorted() accepts an iterable, eg a set, and returns a list: B = sorted(set(A)) --

Re: Organize large DNA txt files

2009-03-20 Thread MRAB
thomasvang...@gmail.com wrote: Dear Fellow programmers, I'm using Python scripts too organize some rather large datasets describing DNA variation. Information is read, processed and written too a file in a sequential order, like this 1+ 1- 2+ 2- etc.. The files that i created contain

Re: Organize large DNA txt files

2009-03-20 Thread MRAB
thomasvang...@gmail.com wrote: Thanks, This works great! I did not know that it is possible to iterate through the file lines with a while function that's conditional on additional lines being present or not. It relies on file.readline() returning an empty string when it's at the end of the

Re: newbie: precision question

2009-03-21 Thread MRAB
Lada Kugis wrote: [snip] Normal integers are up to 10 digits, after which they become long integers, right ? But if integers can be exactly represented, then why do they need two types of integers (long and ... uhmm, let's say, normal). I mean, their error will always be zero, no matter what

Re: Downloading binary files - Python3

2009-03-21 Thread MRAB
Matteo wrote: srcdata = urlopen(url).read() dstfile = open(path,mode='wb') dstfile.write(srcdata) dstfile.close() print(Done!) Have you tried reading all files first, then saving each one on the appropriate directory? It might work if you have enough

Re: Generator

2009-03-22 Thread MRAB
mattia wrote: Can you explain me this behaviour: s = [1,2,3,4,5] g = (x for x in s) next(g) 1 s [1, 2, 3, 4, 5] del s[0] s [2, 3, 4, 5] next(g) 3 Why next(g) doesn't give me 2? First it yields s[0] (which is 1), then you delete s[1], then it yields s[1] (which is now 3). It doesn't

Re: script files with python (instead of tcsh/bash)?

2009-03-22 Thread MRAB
Esmail wrote: Nick Craig-Wood wrote: Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? Yes! .. Almost any script that contains a loop I convert into python. In any case, the scripts are starting to look pretty hairy and I was wondering

Re: safely rename a method with a decorator

2009-03-22 Thread MRAB
Daniel Fetchinson wrote: I'd like to implement a decorator that would rename the method which it decorates. Since it's a tricky thing in general involving all sorts of __magic__ I thought I would ask around first before writing something buggy :) It should work something like this: class

Re: Escaping optional parameter in WHERE clause

2009-03-23 Thread MRAB
someone wrote: Hi, as you can see below I have some optional parameter for my query (mf, age). They are in WHERE clause only if not empty. In this function they are not escaped as, for example, 'search' parameter, cause I can't pass them to execute function, which does escaping automatically.

Re: Syntax error when importing a file which starts with a number

2009-03-23 Thread MRAB
simon.wo...@gmail.com wrote: Hello, all. I don't suppose anyone has any idea why it seems to be impossible to import any file which starts with a number? You get a syntax error, whether the file exists or not. Try it yourself: import foo ImportError: No module named foo import 1foo

Re: Does Python have certificate?

2009-03-24 Thread MRAB
Johannes Bauer wrote: Sebastian Bassi schrieb: No, there is no certification for Python. Maybe in the future... I'll hand out the Johannes Bauer Python Certificate of Total Awesomeness for anyone who can write a hello world in python and hands me $25000 in cash. This whole certified foobar

Re: setting directory mod date

2009-03-24 Thread MRAB
jyoun...@kc.rr.com wrote: I've got some Python code (2.5.1) that's compressing folders on a Windows machine. When the directories get compressed, their modification date changes. Is it possible to grab the modification date of the folder before it's compressed, and then set it's

  1   2   3   4   5   6   7   8   9   10   >