Converting a string to an array?

2006-01-13 Thread Tim Chase
While working on a Jumble-esque program, I was trying to get a string into a character array. Unfortunately, it seems to choke on the following import random s = abcefg random.shuffle(s) returning File /usr/lib/python2.3/random.py, line 250, in shuffle x[i],

gracefully handling broken pipes (was Re: Converting a string to an array?)

2006-01-13 Thread Tim Chase
import random s = abcdefg data = list(s) random.shuffle(data) .join(data) 'bfegacd' fit you better? Excellent! Thanks. I kept trying to find something like an array() function. Too many languages, too little depth. The program was just a short script to scramble the

Re: New Python.org website ?

2006-01-13 Thread Tim Chase
http://beta.python.org In both Mozilla-suite (1.7) and FireFox (1.5), the links on the left (the grey-backgrounded all-caps with the at the right) all intrude into the body text. They're all the same length: ABOUT covers the T in The Official Python... NEWS/DOCUMENTATION/DOWNLOAD all

Re: New Python.org website ?

2006-01-13 Thread Tim Chase
In both Mozilla-suite (1.7) and FireFox (1.5), the links on the left (the grey-backgrounded all-caps with the at the right) all intrude into the body text. Looks fine here on Firefox 1.5 and Konqueror 3.4.3. Just in case anybody is interested, I've posted screenshots of how it comes out

Re: New Python.org website ?

2006-01-16 Thread Tim Chase
The nav styles have crept back in sync with the rest of the site.. ;-) can you check again and tell me if it looks ok (and if not get me another screenie?) Sorry it took so long to get back to you. It looked fine from home, but the originals were snapped back at work (where my configuration

Re: New Python.org website ?

2006-01-17 Thread Tim Chase
I've got an old copy of the html and tried to fix the general problem. It's currently on another website http://pyyaml.org/downloads/masterhtml/ This seems to no longer have the problem and scales nicely no matter which font-size I use. Good work! -tim --

Re: New Python.org website ?

2006-01-18 Thread Tim Chase
At any rate, opinions will always differ. You are always going to get the people who want a cool flash-based animated site with 3D stereo surround sound, and the other end of the spectrum where you will be flamed if you do anything more than hand-code the html, on Unix machines only,

Re: How to set a wx.textctrl can editable or readonly?

2006-01-18 Thread Tim Chase
def onGotFocus(self,evt): if readonly: self.Navigate() This causes the control to react as if the user press 'tab'. By default it always tabs forwards, but it takes an optional 'IsForward' argument - set it to False to tab backwards. Just a pedantic query, not

Re: How to set a wx.textctrl can editable or readonly?

2006-01-19 Thread Tim Chase
Additionally, you should be able to copy text from a read-only control, so ousting the focus may not be quite the right thing to do. Good point. Alternative approaches would be to trap EVT_KEY_DOWN or EVT_TEXT to detect and block attempts to modify the contents of the control. Other

Re: list comprehention

2006-01-19 Thread Tim Chase
Python beginner here and very much enjoying it. I'm looking for a pythonic way to find how many listmembers are also present in a reference list. Don't count duplicates (eg. if you already found a matching member in the ref list, you can't use the ref member anymore). Example1:

Re: list comprehention

2006-01-19 Thread Tim Chase
Python beginner here and very much enjoying it. I'm looking for a pythonic way to find how many listmembers are also present in a reference list. Don't count duplicates (eg. if [snipped] won't set remove duplicates which he wants to preserve ? My reading was that the solution shouldn't

Re: Extended List Comprehension

2006-01-20 Thread Tim Chase
py [x for x in '1234' if x%2 else 'even'] [1, 'even', 3, 'even'] I'm guessing this has been suggested before? You could (in 2.5) use: [(x if x%2 else 'even') for x in '1234'] This failed on multiple levels in 2.3.5 (the if syntax is unrecognized, and trying the below with '1234'

Unified web API for CGI and mod_python?

2006-01-24 Thread Tim Chase
I've been digging around, but can't seem to come up with the right combo of words to google for to get helpful results. Is there some handy wrapper/module that allows code to target existance as both a CGI script and a mod_python script, with only one import statement? Perhaps some common

Re: append to the end of a dictionary

2006-01-24 Thread Tim Chase
I seem to be unable to find a way to appends more keys/values to the end of a dictionary... how can I do that? E.g: mydict = {'a':'1'} I need to append 'b':'2' to it to have: mydict = {'a':'1','b':'2'} my understanding is that the order of a dictionary should never be relied upon.

Re: append to the end of a dictionary

2006-01-24 Thread Tim Chase
that means I can neither have a dictionary with 2 identical keys but different values...? correct :) I would need e.g. this: (a list of ports and protocols, to be treated later in a loop) ports = {'5631': 'udp', '5632': 'tcp', '3389': 'tcp', '5900': 'tcp'} #then: for port,protocol in

Re: append to the end of a dictionary

2006-01-24 Thread Tim Chase
orderedDict = [(k,mydict[k]) for k in mydict.keys().sort()] Unfortunately, the version I've got here doesn't seem to support a sort() method for the list returned by keys(). :( I bet it does, but it doesn't do what you think it does. See http://docs.python.org/lib/typesseq-mutable.html ,

Re: Creating a more random int?

2006-01-24 Thread Tim Chase
I need to retrieve an integer from within a range ... this works ... below is my out puts ... it just does not seem so random ... Is there perhaps a suggestion out there to create a more random int ...? I'm not sure how you determine that it just does not seem so random...I tried the

Best way to extract an item from a set of len 1

2006-01-25 Thread Tim Chase
When you have a set, known to be of length one, is there a best (most pythonic) way to retrieve that one item? # given that I've got Python2.3.[45] on hand, # hack the following two lines to get a set object import sets set = sets.Set s = set(['test']) len(s)

Re: Creating a more random int?

2006-01-25 Thread Tim Chase
Exactly. And I've never heard anyone say to my sons that it's so unusual that they are born on Jan 30th or June 27th! Now those born on Feb 29th...they're about a quarter as frequent :) -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: float formatting

2006-01-25 Thread Tim Chase
for i in range(2,7): print | + %10.if % num2 + | #where i would be the iteration and the num of decimal places for places in range(2,7): ... print |%10.*f| % (places, num2) ... | 42.99| |42.988| | 42.9877| | 42.98765|

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. xyz123aaabbaaabaaaabb I'm looking for a regular expression that matches the first, and only the first, sequence of the

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. Ah...a little more clear. r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] Wow, I like it, but it allows some strings it shouldn't. For example: xyz123aabbaaab (It skips over the two-letter sequence of 'a' and matches 'bbaaab'.) Anchoring it to the beginning/end might

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
The below seems to pass all the tests you threw at it (taking the modified 2nd test into consideration) One other test that occurs to me would be xyz123aaabbaaabab where you have aaab in there twice. -tkc import re tests = [ (xyz123aaabbab,True), (xyz123aabbaaab, False),

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
xyz123aaabbaaabab where you have aaab in there twice. Good suggestion. I assumed that this would be a valid case. If not, the expression would need tweaking. ^([^b]|((?!a)b))*aaab+[ab]*$ Looks good, although I've been unable to find a good explanation of the negative lookbehind

Re: 2-dimensional data structures

2006-01-26 Thread Tim Chase
I want to work on a sudoku brute-forcer, just for fun. Well, as everybody seems to be doing these (self included...), the sudoku solver may become the hello world of the new world :) What is the equivalent way to store data in python? - It isn't obvious to me how to do it with lists.

Re: writing large files quickly

2006-01-27 Thread Tim Chase
Untested, but this should be faster. block = '0' * 409600 fd = file('large_file.bin', 'wb') for x in range(1000): fd.write('0') fd.close() Just checking...you mean fd.write(block) right? :) Otherwise, you end up with just 1000 0 characters in your file :) Is there

Re: writing large files quickly

2006-01-27 Thread Tim Chase
fd.write('0') [cut] f = file('large_file.bin','wb') f.seek(40960-1) f.write('\x00') While a mindblowingly simple/elegant/fast solution (kudos!), the OP's file ends up with full of the character zero (ASCII 0x30), while your solution ends up full of the NUL character (ASCII 0x00):

Re: Question about idioms for clearing a list

2006-01-31 Thread Tim Chase
I know that the standard idioms for clearing a list are: (1) mylist[:] = [] (2) del mylist[:] I guess I'm not in the slicing frame of mind, as someone put it, but can someone explain what the difference is between these and: (3) mylist = [] Why are (1) and (2) preferred? I

Re: path to python in WinXP

2006-01-31 Thread Tim Chase
I have a real newbie question here. Well, as a starter, it would be helpful if you included a Subject: line in your mail...my spam filters flagged it and I almost tossed it in my bit-bucket because the subject was empty. :*) On WinXP I open a command line and type 'python' and get 'PYTHON'

Re: Regular expression query

2006-02-03 Thread Tim Chase
parameter=12ab parameter=12ab foo bar parameter='12ab' parameter='12ab' biz boz parameter=12ab parameter=12ab junk in each case returning 12ab as a match. parameter is known and fixed. The parameter value may or may not be enclosed in single or double quotes, and may or may not be the

Re: numeric expression from string?

2006-02-04 Thread Tim Chase
I have a string input from the user, and want to parse it to a number, and would like to know how to do it. I would like to be able to accept arithmetic operations, like: '5+5' '(4+3)*2' '5e3/10**3' I thought of using eval, which will work, but could lead to bad security problems

Re: breadth first search

2006-02-08 Thread Tim Chase
Anyone know how to implement breadth first search using Python? Yes. Granted, for more details, you'd have to describe the data structure you're trying to navigate breadth-first. Can Python create list dynamically Is Perl write-only? Does Lisp use too many parens? Of course! :) Not only

Re: breadth first search

2006-02-08 Thread Tim Chase
Thanks for your reply and the structure of the file structure going to be read is total number of nodes first nodesecond nodedistance from first node to second node ... end of file represented by -1 The aims is to find out the shortest path(s) for the leaf node(s) Example: 9 0 1 1

Re: What editor shall I use?

2006-02-08 Thread Tim Chase
I myself have just begun using vim. Does anyone have any tips/convenient tweaks for python programming with it? For python programming several settings can make life far less painful (assuming you like 4-spaces-per-tab) : set ai ts=4 sw=4 et or set ai ts=4 sw=4 noet

Re: newbie needs serious help

2006-02-09 Thread Tim Chase
I downloaded the Python 2.4.2 msi file, and installed it. All went well. Now, I have no idea what to do. I read the documentation, README files, etc., and it looks like I'm supposed to configure it with a ./configure command,and then a magical make command. I suspect you were reading

Re: is there a better way?

2006-02-10 Thread Tim Chase
You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X. There are never O's between X's. I have been using

Re: looping over more than one list

2006-02-16 Thread Tim Chase
def lowest(s1,s2): s = for i in xrange(len(s1)): s += lowerChar(s1[i],s2[i]) return s this seems unpythonic, compared to something like: def lowest(s1,s2): s = for c1,c2 in s1,s2: s += lowerChar(c1,c2) return s If I understand correctly,

Re: Detec nonascii in a string

2006-02-23 Thread Tim Chase
How do I detect non-ascii letters in a string? I want to detect the condition that a string have a letter that is not here: string.ascii_letters I don't know how efficient it is, but it's fairly clean: clean_string = ''.join([c for c in some_string if c in string.ascii_letters]) If you

wxPython: help(wx) causes segfaulting?

2006-02-26 Thread Tim Chase
Trying to get my feet wet with wxPython (moving from just command-line apps), I tried the obvious (or, at least to me was obvious): Start python, import wx and then do a help(wx) to see what it can tell me. Unfortunately, it spewed back a handful of errors, gasped, wheezed and died

Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Tim Chase
Let's say I have two dictionaries: dict1 is 1:23, 2:76, 4:56 dict2 is 23:A, 76:B, 56:C How do I get a dictionary that is 1:A, 2:B, 4:C d1={1:23,2:76,4:56} d2={23:a, 76:b, 56:c} result = dict([(d1k,d2[d1v]) for (d1k, d1v) in d1.items()]) result {1: 'a', 2: 'b', 4: 'c'} If

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Tim Chase
Uniqueness imposes an odd constraint that you can't have synonyms in the set: shades = enum({white:100, grey:50, gray:50, black:0}) Blast, I hate responding to my own posts, but as soon as I hit Send, I noticed the syntax here was biffed. Should have been something like shades =

Re: Looking for library to estimate likeness of two strings

2008-02-06 Thread Tim Chase
Are there any Python libraries implementing measurement of similarity of two strings of Latin characters? It sounds like you're interested in calculating the Levenshtein distance: http://en.wikipedia.org/wiki/Levenshtein_distance which gives you a measure of how different they are. A

Re: a trick with lists ?

2008-02-07 Thread Tim Chase
self.tasks[:] = tasks What I do not fully understand is the line self.tasks[:] = tasks. Why does the guy who coded this did not write it as self.tasks = tasks? What is the use of the [:] trick ? It changes the list in-place. If it has been given to other objects, it might

Re: beginners help

2008-02-07 Thread Tim Chase
If i enter a center digit like 5 for example i need to create two vertical and horzitonal rows that looks like this. If i enter 6 it shows 6 six starts. How can i do this, because i don't have any clue. * * * * * * * * Well we start by introducing the neophite programmer to

Re: Better way to do this?

2008-02-11 Thread Tim Chase
I have a tuple of tuples, in the form-- ((code1, 'string1'),(code2, 'string2'),(code3, 'string3'),) Codes are unique. A dict would probably be the best approach but this is beyond my control. Here is an example: pets = ((0,'cat'),(1,'dog'),(2,'mouse')) If I am given a value for the

Re: how to find current working user

2008-02-11 Thread Tim Chase
Can anyone tell me how to find current working user in windows? The below should be fairly cross-platform: import getpass whoami = getpass.getuser() print whoami W: tchase L: tim (W: is the result on my windows box, L: is the result on my Linux box) which can be used in concert

Re: dream hardware

2008-02-12 Thread Tim Chase
What is dream hardware for the Python interpreter? The only dream hardware I know of is the human brain. I have a slightly used one myself, and it's a pretty mediocre Python interpreter. the human brain may be a pretty mediocre Python interpreter, but darn if I don't miss import dwim

Re: copying files through Python

2008-02-13 Thread Tim Chase
I am new to python. Infact started yesterday and feeling out of place. I need to write a program which would transfer files under one folder structure (there are sub folders) to single folder. Can anyone give me some idea like which library files or commands would be suitable for this file

Re: Complicated string substitution

2008-02-13 Thread Tim Chase
I have a file with a lot of the following ocurrences: denmark.handa.1-10 denmark.handa.1-12344 denmark.handa.1-4 denmark.handa.1-56 Each on its own line? Scattered throughout the text? With other content that needs to be un-changed? With other stuff on the same line?

Re: Solve a Debate

2008-02-15 Thread Tim Chase
Ok the problem we had been asked a while back, to do a programming exercise (in college) That would tell you how many days there are in a month given a specific month. Ok I did my like this (just pseudo): If month = 1 or 3 or etc noDays = 31 Elseif month = 4 or 6 etc

Re: Help Parsing an HTML File

2008-02-15 Thread Tim Chase
I need to parse the file in such a way to extract data out of the html and to come up with a tab separated file that would look like OUTPUT- FILE below. BeautifulSoup[1]. Your one-stop-shop for all your HTML parsing needs. What you do with the parsed data, is an exercise left to the reader,

Re: simple python script to zip files

2008-02-16 Thread Tim Chase
I'm just starting to learn some Python basics and are not familiar with file handling. Looking for a python scrip that zips files. So aaa.xx bbb.yy ccc.xx should be zipped to aaa.zip bbb.zip ccc.zip I haven't been able to type more than 'import gzip'.. Well, you ask for zip files, but

Re: simple python script to zip files

2008-02-16 Thread Tim Chase
Thanks! Works indeed. Strange thing is though, the files created are the exact size as the original file. So it seems like it is zipping without compression. The instantiation of the ZipFile object can take an optional parameter to control the compression. The zipfile module only supports

Re: copying files through Python

2008-02-16 Thread Tim Chase
OP stated requirements were to move all the files into a single folder. Copytree will preserve the directory structure from the source side of the copy operation. well, it would be copying [not moving] files through Python, but if the desire is to flatten the tree into a single directory,

Re: What's the standard for code docs?

2008-02-19 Thread Tim Chase
HTML. Text-only docs are so last-cen. My sarcasometer is broken today... are you being serious? man serious As opposed to woman serious? [EMAIL PROTECTED]:~$ man -k serious serious: nothing appropriate. -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: Article of interest: Python pros/cons for the enterprise

2008-02-20 Thread Tim Chase
You Used Python to Write WHAT? http://www.cio.com/article/185350 Furthermore, the power and expressivity that Python offers means that it may require more skilled developers. [...down to the summary...] Python may not be an appropriate choice if you: [...] * Rely on teams of less-experienced

Re: packing things back to regular expression

2008-02-20 Thread Tim Chase
mytable = {a : myname} re.SomeNewFunc(compilexp, mytable) myname how does SomeNewFunc know to pull a as opposed to any other key? mytable = {a : 1} re.SomeNewFunc(compileexp, mytable) ERROR You could do something like one of the following 3 functions: import re ERROR = 'ERROR'

Re: Article of interest: Python pros/cons for the enterprise

2008-02-21 Thread Tim Chase
Newbies learn, and the fundamental C++ lessons are usually learnt quite easily. Ah yes...that would be why Scott Meyers has written three volumes[1] cataloging the gotchas that even experienced C++ programmers can make... And the 1030 page Stroustrup C++ reference is easily comprehended by

Re: Script Running Time

2008-02-21 Thread Tim Chase
I am trying to find a way to output how long a script took to run. Obviously the print would go at the end of the script, so it would be the time up till that point. I also run a PostgreSQL query inside the script and would like to separately show how long the query took to run. Is this

Re: Order in which modules are imported

2008-02-22 Thread Tim Chase
import random from pylab import * x = random.uniform(0,1) Traceback (most recent call last): I suspect that 'random' in dir(pylab) returns True...this would be one of those reasons that from module import * is scowled upon. You have to know what module is dumping into your namespace,

Re: most loved template engine on python is?

2008-02-24 Thread Tim Chase
AFAIK, there is no single blessed template system. If you're up to web development then your choice of framework will limit the choices for template engines. For example if you choose Django I guess you'll have to stick with its built-in template system (I might be wrong on this) Django's

Re: Last 4 Letters of String

2008-02-25 Thread Tim Chase
How would you get the last 4 items of a list? Did you try the same get the last 4 items solution that worked for a string? lst[-4:] -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: Python for web...

2008-02-25 Thread Tim Chase
I didn't have any trouble setting up mod_python Django. However, I am my own hosting provider. That may make a difference. ;-) I can install fastcgi if it's a big win. From my understanding, the python-code under mod_python runs as whatever Apaches runs as (www, wwwdata, whatever). If

Re: String compare question

2008-02-25 Thread Tim Chase
ignored_dirs = ( r.\boost\include, # It's that comma that makes this a tuple. ) Thanks for reminding me of this. I always forget that! Now that it is correctly doing *only* whole string matches, what if I want to make it do a substring compare to each string in my ignored_dirs

Re: bin2chr(01110011) # = 15 function ?

2008-02-25 Thread Tim Chase
I'm searching for a simple bin2chr(01110011) function that can convert all my 8bit data to a chr so I can use something like this: print ord(s) # = 115 print bin(ord(s)) # = 01110011 test= open('output.ext,'wb') test.write(bin2chr(01110011)) test.write(bin2chr(0011))

Re: Order of evaluation in conditionals

2008-02-25 Thread Tim Chase
if (condition1) and (condition2) and (condition3): do_something() Is there a guarantee that Python will evaluate those conditions in order (1, 2, 3)? I know I can write that as a nested if, and avoid the problem altogether, but now I'm curious about this ;). Yes, Python does

Re: Break lines?

2008-02-26 Thread Tim Chase
I have made this string: TITLE = 'Efficiency of set operations: sort model, (cphstl::set::insert(p,e)^n cphstl::set::insert(e)), integer' But I am not allowed to break the line like that: IndentationError: unexpected indent How do I break a line? Depends on

Re: Break lines?

2008-02-26 Thread Tim Chase
Ok thanks! Btw why double quotes instead of single ' ? Either one will do...there's not much difference. I try to use double-quotes most of the time, just so when I include an apostrophe in-line (which I do more often than I include a double-quote in-line), I don't have to think.

Making string-formatting smarter by handling generators?

2008-02-27 Thread Tim Chase
Is there an easy way to make string-formatting smart enough to gracefully handle iterators/generators? E.g. transform = lambda s: s.upper() pair = ('hello', 'world') print %s, %s % pair # works print %s, %s % map(transform, pair) # fails with a TypeError: not enough arguments for

Re: Making string-formatting smarter by handling generators?

2008-02-27 Thread Tim Chase
Is there an easy way to make string-formatting smart enough to gracefully handle iterators/generators? E.g. transform = lambda s: s.upper() pair = ('hello', 'world') print %s, %s % pair # works print %s, %s % map(transform, pair) # fails with a TypeError: not enough

Re: Making string-formatting smarter by handling generators?

2008-02-27 Thread Tim Chase
Note that your problem has nothing to do with map itself. String interpolation using % requires either many individual arguments, or a single *tuple* argument. A list is printed as itself. Just as an exercise to understand this better, I've been trying to figure out what allows for this

Re: joining strings question

2008-02-29 Thread Tim Chase
I have some data with some categories, titles, subtitles, and a link to their pdf and I need to join the title and the subtitle for every file and divide them into their separate groups. So the data comes in like this: data = ['RULES', 'title','subtitle','pdf',

Re: joining strings question

2008-02-29 Thread Tim Chase
I V wrote: On Fri, 29 Feb 2008 08:18:54 -0800, baku wrote: return s == s.upper() A couple of people in this thread have used this to test for an upper case string. Is there a reason to prefer it to s.isupper() ? For my part? forgetfulness brought on by underuse of .isupper() -tkc --

Re: Where's GUI for Python?

2008-03-01 Thread Tim Chase
I'm certain there is an API for creating GUI's but as far i can find it in the http://docs.python.org/tut/tut.html the only gui is in Guido. What do i miss? The batteries-included GUI: import tkininter Add-on solutions include wxPython, PythonCard and many others. GIYF:

Re: A python STUN client is ready on Google Code.

2008-03-01 Thread Tim Chase
|I upload a new version. Add more print log into my code to help people | understand my program Announcements should include a short paragraph explaining what the announcement is about for those of us not in the know. IE, what is STUN? -- and therefore, what is a STUN client? I believe

Re: for-else

2008-03-04 Thread Tim Chase
For instance, if you have a (trivial) if...elif...else like this: if a == 0: do_task_0() elif a == 1: do_task_1() elif a == 2: do_task_2() else: do_default_task() You could roll it up into a for...else statement like this: for i in range(3): if a == i:

Re: Python an Exchange Server

2008-03-04 Thread Tim Chase
Hi friends. Someone know how to work with python and exchange server?. I've used both imaplib[1] and smtplib[2] (in the standard library) for talking successfully with an Exchange server. I don't do much with POP3, but there's also a poplib module[3] in the standard library. I just wrote

Re: sqlite3 permission issue

2008-03-04 Thread Tim Chase
I am trying to execute an update to a sqlite3 db via a python cgi If you're running as a CGI, your script (as you guess below) will usually run with the effective permissions of the web-server. Frequently, this is some user such as wwwdata or www. conn = sqlite3.connect('db') Make sure that

Re: Using re module better

2008-03-05 Thread Tim Chase
if (match = re.search('(\w+)\s*(\w+)', foo)): Caveat #1: use a raw string here Caveat #2: inline assignment is verboten match = re.search(r'(\w+)\s*(\w*+)', foo) if match: field1 = match.group(1) field2 = match.group(2) This should then work more or less. However, since you

Re: Exploring Attributes and Methods

2008-03-06 Thread Tim Chase
Class Sample: fullname = 'Something' How can I know that this class has an attribute called 'fullname'? with the builtin hasattr() function :) class Sample: fullname='Something' ... hasattr(Sample, 'fullname') True -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: I cannot evaluate this statement...

2008-03-07 Thread Tim Chase
import os, sys pyfile = (sys.platform[:3] == 'win' and 'python.exe') or 'python' Okay, run on a win32 machine, pyfile evaluates to python.exe [snip] Now. Run this on linux. The first condition evaluates sys.platform[:3] == 'win' as false. [snip] Where am I going wrong. And when will this

Re: Intelligent Date Time parsing

2008-03-08 Thread Tim Chase
I am a GNU newbie. (I know C o.) Can you point me to a place to find the source for 'date'? It's part of the GNU Coreutils: http://ftp.gnu.org/gnu/coreutils/ Within the file, you're likely interested in lib/getdate.* It helps if you have a working knowledge of Yacc. -tkc --

Re: any chance regular expressions are cached?

2008-03-09 Thread Tim Chase
s=re.sub(r'\n','\n'+spaces,s) s=re.sub(r'^',spaces,s) s=re.sub(r' *\n','\n',s) s=re.sub(r' *$','',s) s=re.sub(r'\n*$','',s) Is there any chance that these will be cached somewhere, and save me the trouble of having to declare some global re's if I don't want to have

Re: parsing directory for certain filetypes

2008-03-10 Thread Tim Chase
i wrote a function to parse a given directory and make a sorted list of files with .txt,.doc extensions .it works,but i want to know if it is too bloated..can this be rewritten in more efficient manner? here it is... from string import split from os.path import isdir,join,normpath from

Re: lowercase u before string in python for windows

2008-03-10 Thread Tim Chase
why does this occur when using the python windows extensions? all string are prefixed by a lowercase u. They are Unicode strings: http://docs.python.org/ref/strings.html is there a newsgroup explicitly for python windows extensions? Not that I know of, other than what's described here:

Re: parsing directory for certain filetypes

2008-03-11 Thread Tim Chase
royG wrote: On Mar 10, 8:03 pm, Tim Chase wrote: In Python2.5 (or 2.4 if you implement the any() function, ripped from the docs[1]), this could be rewritten to be a little more flexible...something like this (untested): that was quite a good lesson for a beginner like me.. thanks guys

Re: agg (effbot)

2008-03-12 Thread Tim Chase
Gerhard Häring wrote: [EMAIL PROTECTED] wrote: aggdraw-1.2a3-20060212.tar.gz Try shegabittling the frotz first. If that doesn't help, please post the output of the compile command that threw the error. Maynard: He who is valiant and pure of spirit may find the compiling instructions in

Re: Is there Python equivalent to Perl BEGIN{} block?

2008-03-12 Thread Tim Chase
The subject says pretty much all, Given what I understand about the BEGIN block[1], this is how Python works automatically: bash$ cat a.py print 'a1' import b print 'a2' bash$ cat b.py print 'b' bash$ python a.py a1 b a2 However, the first import does win and

Re: enums and PEP 3132

2008-03-12 Thread Tim Chase
Currently I'm just putting this at the top of the file: py=1 funcpre=2 funcpost=3 ... That can be done more compactly with py, funcpre, funcpost = range(3) I've harbored a hope that a combination of PEP 3132[1] (Extended Iterable unpacking) and

Re: string / split method on ASCII code?

2008-03-12 Thread Tim Chase
I have these annoying textilfes that are delimited by the ASCII char for (only its a single character) and (again a single character) Their codes are 174 and 175, respectively. My datafiles are in the moronic form XYZ I need to split on those freaking characters. Any tips on how

Re: find string in file

2008-03-14 Thread Tim Chase
I'm neophite about python, my target is to create a programa that find a specific string in text file. How can do it? FNAME1 = 'has.txt' FNAME2 = 'doesnt_have.txt' TEXT = 'thing to search for' TEXT in file(FNAME1).read() True TEXT in file(FNAME2).read() False or that may not be

Re: PODCasts

2008-03-19 Thread Tim Chase
I really should say net cast as I think it's a better term ;) Does anyone have any recommended net casts on Python, or programming in general? Well, though it's been a while since I last noticed a new release (last one dated Dec '07), the archives of Python 411 should all be online:

Re: Search the command history - Python Shell

2008-03-19 Thread Tim Chase
Are there any simillar key combination in Python Shell like Linux Ctrl+R (reverse-i-search) to search the command history? It must depend on how your version of Python was built...mine here on my Linux box has exactly that functionality. I press ^R and start typing, and the line comes up

Re: a beginner, beginners question

2008-03-19 Thread Tim Chase
class example: def __init__(self, foo, bar): self.foo = foo self.bar = bar def method(self): print method ... : print self.foo print self.bar if __name__ == __main__: obj = example This makes obj a synonym for example. You want

Re: url validator in python

2008-03-19 Thread Tim Chase
How can I check the validity of absolute urls with http scheme? example: http://www.example.com/something.html; - valid http://www.google.com/ + Brite_AB_Iframe_URL + - invalid You could try something like import urllib tests = ( (http://www.google.com/ + Brite_AB_Iframe_URL + ,

Re: beginners question about return value of re.split

2008-03-21 Thread Tim Chase
datum = 2008-03-14 the_date = re.split('^([0-9]{4})-([0-9]{2})-([0-9]{2})$', datum, 3) print the_date Now the result that is printed is: ['', '2008', '03', '14', ''] My question: what are the empty strings doing there in the beginning and in the end ? Is this due to a

Re: Does python hate cathy?

2008-03-23 Thread Tim Chase
When I run this script, I got the following exception: Exception exceptions.AttributeError: 'NoneType' object has no attribute 'population' in bound method Person.__del__ of __main__.Person instance at 0xb7d8ac6c ignored To to newcomer like me, this message doesn't make much sense. What

Re: any good g.a.'s?

2008-03-25 Thread Tim Chase
Any good genetic algorithms involving you-split, i-pick? I've always heard it as you divide, I decide... That said, I'm not sure how that applies in a GA world. It's been a while since I've done any coding with GAs, but I don't recall any facets related to the You Divide, I Decide problem.

Re: what does ^ do in python

2008-03-25 Thread Tim Chase
In most of the languages ^ is used for 'to the power of'. No, not in most languages. In most languages (C, C++, Java, C#, Python, Fortran, ...), ^ is the xor operator ;) ...and in Pascal it's the pointer-dereferencing operator... -tkc --

  1   2   3   4   5   6   7   8   9   10   >