RE: type hinting backward compatibility with python 3.0 to 3.4

2017-05-19 Thread Edward Ned Harvey (python)
This pattern seems to work: import sys if sys.version_info[0] < 3: raise RuntimeError("Must use at least python version 3") # The 'typing' module, useful for type hints, was introduced in python 3.5 if sys.version_info[1] >= 5: from typing import Optional optional_float = Optional[fl

type hinting backward compatibility with python 3.0 to 3.4

2017-05-19 Thread Edward Ned Harvey (python)
I think it's great that for built-in types such as int and str, backward compatibility of type hinting annotations is baked into python 3.0 to 3.4. In fact, I *thought* python 3.0 to 3.4 would *ignore* annotations, but it doesn't... I'm struggling to create something backward compatible that re

Error with math.sqrt

2017-01-07 Thread Jack Harvey
I'm starting out with Python 3.5. My current frustration is with: >>> math.sqrt(25) Traceback (most recent call last): File "", line 1, in math.sqrt(25) NameError: name 'math' is not defined >>> Advice? Jack -- https://mail.python.org/mailman/listinfo/python-list

variable attribute name

2014-10-27 Thread Harvey Greenberg
I want to let the name of an attribute be the string value of a variable. Here is some code: class Object(object): pass A = Object() s = 'attr' A. = 1 The last line denotes the variable value by (not a python form). What I want is to have A.attr = 1, but 'attr' determined by the value of s.

Re: how to read list from file

2013-10-06 Thread Harvey Greenberg
On Saturday, October 5, 2013 7:08:08 PM UTC-6, Harvey Greenberg wrote: > I am looping as for L in file.readlines(), where file is csv. > > > > L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that the first > item is a dir and 2nd is a li

Re: how to read list from file

2013-10-06 Thread Harvey Greenberg
On Sunday, October 6, 2013 10:41:33 AM UTC-6, Harvey Greenberg wrote: > On Saturday, October 5, 2013 7:24:39 PM UTC-6, Tim Chase wrote: > > > On 2013-10-05 18:08, Harvey Greenberg wrote: > > > > > > > I am looping as for L in fi

Re: how to read list from file

2013-10-06 Thread Harvey Greenberg
On Saturday, October 5, 2013 7:24:39 PM UTC-6, Tim Chase wrote: > On 2013-10-05 18:08, Harvey Greenberg wrote: > > > I am looping as for L in file.readlines(), where file is csv. > > > > > > L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3]

how to read list from file

2013-10-05 Thread Harvey Greenberg
I am looping as for L in file.readlines(), where file is csv. L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that the first item is a dir and 2nd is a list, so parsing with split doesn't work. Is there a way to convert L, which is a string, to the list of 3 items I want? -- ht

Re: Memory error due to big input file

2009-07-13 Thread Vilya Harvey
2009/7/13 Aaron Scott : >> BTW, you should derive all your classes from something.  If nothing >> else, use object. >>   class textfile(object): > > Just out of curiousity... why is that? I've been coding in Python for > a long time, and I never derive my base classes. What's the advantage > to der

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Vilya Harvey
2009/7/13 seldan24 : > Thank you both for your input.  I want to make sure I get started on > the right track.  For this particular script, I should have included > that I would take the exception contents, and pass those to the > logging module.  For this particular script, all exceptions are fata

Re: Question about generators

2009-07-12 Thread Vilya Harvey
2009/7/12 Cameron Pulsford : > My question is, is it possible to combine those two loops? The primes > generator I wrote finds all primes up to n, except for 2, 3 and 5, so I must > check those explicitly. Is there anyway to concatenate the hard coded list > of [2,3,5] and the generator I wrote so

Re: count

2009-07-08 Thread Vilya Harvey
2009/7/8 Dhananjay : > I wanted to sort column 2 in assending order  and I read whole file in array > "data" and did the following: > > data.sort(key = lambda fields:(fields[2])) > > I have sorted column 2, however I want to count the numbers in the column 2. > i.e. I want to know, for example, how

Re: Why is my code faster with append() in a loop than with a large list?

2009-07-06 Thread Vilya Harvey
2009/7/6 Xavier Ho : > Why is version B of the code faster than version A? (Only three lines > different) Here's a guess: As the number you're testing gets larger, version A is creating very big list. I'm not sure exactly how much overhead each list entry has in python, but I guess it's at least

Re: finding most common elements between thousands of multiple arrays.

2009-07-04 Thread Vilya Harvey
2009/7/4 Steven D'Aprano : > On Sat, 04 Jul 2009 13:42:06 +, Steven D'Aprano wrote: > >> On Sat, 04 Jul 2009 10:55:44 +0100, Vilya Harvey wrote: >> >>> 2009/7/4 Andre Engels : >>>> On Sat, Jul 4, 2009 at 9:33 AM, mclovin wrote: >>&

Re: Reversible Debugging

2009-07-04 Thread Vilya Harvey
2009/7/4 Patrick Sabin : > If someone has another idea of taking a snapshot let me know. Using VMWare > is not a > very elegant way in my opinion. Someone implemented the same idea for Java a while ago. They called it "omniscient debugging"; you can find details at http://www.lambdacs.com/debu

Re: finding most common elements between thousands of multiple arrays.

2009-07-04 Thread Vilya Harvey
2009/7/4 Andre Engels : > On Sat, Jul 4, 2009 at 9:33 AM, mclovin wrote: >> Currently I need to find the most common elements in thousands of >> arrays within one large array (arround 2 million instances with ~70k >> unique elements) >> >> so I set up a dictionary to handle the counting so when I a

Python/Django Developer

2008-10-24 Thread harvey
My client in Jersey City, NJ 07302 is looking for a Python Developer. Below is the job description: Job Summary: This is a programming position in the technical department of Advance Internet, working on application development, application integration, automated testing and deployment of appli

Re: Issue with regular expressions

2008-04-29 Thread harvey . thomas
t;': #strip off the quotes and normalise spaces ret.append(' '.join(x[1:-1].split())) else: ret.append(x) return ret query = ' " Some words" withand "withoutquotes " ' print findwords(query) Running this gives ['Some words', 'with', 'and', 'without quotes'] HTH Harvey -- http://mail.python.org/mailman/listinfo/python-list

Re: Matching XML Tag Contents with Regex

2007-12-11 Thread harvey . thomas
]* portion of my > regex is being ignored, so only one match is being returned, starting > at the first and ending at the end of the text, when it should > end at the first . For this example, it should return three > matches, one for each div. > > Is what I'm trying to do possible with Python's Regex library? Is > there an error in my Regex? > > Thanks, > Chris print re.findall(r'<%s(?=[\s/>])[^>]*>' % 'div', r) ["", "", ""] HTH Harvey -- http://mail.python.org/mailman/listinfo/python-list

SMTPLIB & email.MIMEText : Certain charaters in the body stop mail from arriving. Why?

2007-11-29 Thread West, Harvey
Hello Sending mail with certain characters in the body causes mail never to arrive. Why? e.g if body text has a fullstop "." mail never arrives. I'm using python 4.2 on windows. Harvey #

Re: just a bug (was: xml.dom.minidom: how to preserve CRLF's inside CDATA?)

2007-05-25 Thread harvey . thomas
range(0x20, 0xD7FF), iMessage)- Hide quoted > text - > > - Show quoted text - You need to explicitly convert the string of UTF8 encoded bytes to a Unicode string before parsing e.g. unicodestring = unicode(encodedbytes, 'utf8') Unless I messed up copying and pasting, your

Re: xml.dom.minidom: how to preserve CRLF's inside CDATA?

2007-05-22 Thread harvey . thomas
On May 22, 2:45 pm, "sim.sim" <[EMAIL PROTECTED]> wrote: > Hi all. > i'm faced to trouble using minidom: > > #i have a string (xml) within CDATA section, and the section includes > "\r\n": > iInStr = '\n\n' > > #After i create DOM-object, i get the value of "Data" without "\r\n" > > from xml.dom im

Re: XML Parsing

2007-03-28 Thread harvey . thomas
s not valid XML. It misses a xmlns:text namespace > declaration. So you won't be able to parse it regardless of what parser you > use. > > Diez- Hide quoted text - > > - Show quoted text - The example is valid well-formed XML. It is permitted to use the ":" character in element names. Whether one should in a non namespace context is a different matter. Harvey -- http://mail.python.org/mailman/listinfo/python-list

Re: Match 2 words in a line of file

2007-01-19 Thread harvey . thomas
Rickard Lindberg wrote: > I see two potential problems with the non regex solutions. > > 1) Consider a line: "foo (bar)". When you split it you will only get > two strings, as split by default only splits the string on white space > characters. Thus "'bar' in words" will return false, even though

Re: Match 2 words in a line of file

2007-01-19 Thread harvey . thomas
Rickard Lindberg wrote: > I see two potential problems with the non regex solutions. > > 1) Consider a line: "foo (bar)". When you split it you will only get > two strings, as split by default only splits the string on white space > characters. Thus "'bar' in words" will return false, even though

Re: One more regular expressions question

2007-01-18 Thread harvey . thomas
Victor Polukcht wrote: > My pattern now is: > > (?P[^(]+)(?P\d+)\)\s+(?P\d+) > > And i expect to get: > > var1 = "Unassigned Number " > var2 = "1" > var3 = "32" > > I'm sure my regexp is incorrect, but can't understand where exactly. > > Regex.debug shows that even the first block is incorrect. >

Re: re.sub and empty groups

2007-01-16 Thread harvey . thomas
Hugo Ferreira wrote: > Hi! > > I'm trying to do a search-replace in places where some groups are > optional... Here's an example: > > >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola").groups() > ('ola', None) > > >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola|").groups() > ('ola', '')

Re: re.sub and empty groups

2007-01-16 Thread harvey . thomas
Hugo Ferreira wrote: > Hi! > > I'm trying to do a search-replace in places where some groups are > optional... Here's an example: > > >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola").groups() > ('ola', None) > > >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola|").groups() > ('ola', '')

Re: Need a Regular expression to remove a char for Unicode text

2006-10-13 Thread harvey . thomas
శ్రీనివాస wrote: > Hai friends, > Can any one tell me how can i remove a character from a unocode text. > కల్‌&హార is a Telugu word in Unicode. Here i want to > remove '&' but not replace with a zero width char. And one more thing, > if any whitespaces are there before and after '&' char, the text

Re: Insert characters into string based on re ?

2006-10-13 Thread harvey . thomas
Matt wrote: > I am attempting to reformat a string, inserting newlines before certain > phrases. For example, in formatting SQL, I want to start a new line at > each JOIN condition. Noting that strings are immutable, I thought it > best to spllit the string at the key points, then join with '\n'.

Re: efficiency question

2006-06-30 Thread David Harvey
Fredrik Lundh wrote: > when in doubt, ask the compiler: MTD wrote: > >>> dis.dis(cod) Thanks so much guys! Python just gets cooler every day! David -- http://mail.python.org/mailman/listinfo/python-list

efficiency question

2006-06-30 Thread David Harvey
Hi, Suppose I write if x in ("abc", "def", "xyz"): doStuff() elif x in ("pqr", "tuv", "123"): doOtherStuff() elif ... etc. When is python building the tuples? Does it need to build the tuple every time it comes through this code? Or do