RE: something about split()???

2012-08-14 Thread Andreas Tawn
I have a question about the split function? surpose a = |,and when I use a.split(|) , I got the list [',] ,but I want to get the empty list,what should I do ? Something like... [x for x in |.split(|) if x] [] Cheers, Drea -- http://mail.python.org/mailman/listinfo/python-list

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-14 Thread Andreas Tawn
p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal interest (or perhaps both)? We do use Python a fair bit, mostly for build systems and data mining, but also because it's the built-in script language for Motionbuilder. --

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
This issue bit me once too often a few months ago, and now I have a class called O from which I often subclass instead of from object. Its main purpose is a friendly __str__ method, though it also has a friendly __init__. Code: class O(object): ''' A bare object subclass to

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
I have no idea why using __repr__ versus __str__ would make any difference in the order of the attributes. They're going to come out in the order you specify, regardless of what you name your method. If you don't like the arbitrary order you get from the dictionary, then either sort it,

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
It's also helpful to not have to display every attribute, of which there may be dozens. Do I detect a code smell here? Possibly. I'll often try to subdivide into several simpler types, but sometimes that makes the code more complex than it needs to be. --

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
It's also helpful to not have to display every attribute, of which there may be dozens. Do I detect a code smell here? I think so, Murphy's law dictates that the attribute you're interested in will not be displayed anyway. That's what __repr__'s for. --

Dealing with the __str__ method in classes with lots of attributes

2012-05-10 Thread Andreas Tawn
Say I've got a class... class test(object): def __init__(self): self.foo = 1 self.bar = 2 self.baz = 3 I can say... def __str__(self): return foo: {0}\nbar: {1}\nbaz: {2}.format(self.foo, self.bar, self.baz) and everything's simple and clean and I can vary the

RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-10 Thread Andreas Tawn
On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn andreas.t...@ubisoft.com wrote: Say I've got a class... class test(object):    def __init__(self):        self.foo = 1        self.bar = 2        self.baz = 3 I can say... def __str__(self):   return foo: {0}\nbar: {1}\nbaz

RE: starting a separate thread in maya

2011-05-20 Thread Andreas Tawn
Hi, I'm using python2.5 in maya 2009 x64 (in linux). For Maya/Python stuff you'll probably have more success at http://www.tech-artists.org/ Cheers, Drea -- http://mail.python.org/mailman/listinfo/python-list

RE: Python sets which support multiple same elements

2011-05-20 Thread Andreas Tawn
For example, I was writing a program to detect whether two strings are anagrams of each other. I had to write it like this: def isAnagram(w1, w2): w2=list(w2) for c in w1: if c not in w2: return False else: w2.remove(c) return True But if there was a data

RE: What other languages use the same data model as Python?

2011-05-05 Thread Andreas Tawn
Steven D'Aprano wrote: Some day, we'll be using quantum computers without memory addresses, [ ... ] it will still be possible to represent data indirectly via *some* mechanism. :) Cool! Pass-by-coincidence! And Python 3 already has dibs on the 'nonlocal' keyword! Mel.

RE: Vectors

2011-04-20 Thread Andreas Tawn
Algis Kabaila akaba...@pcug.org.au writes: Are there any modules for vector algebra (three dimensional vectors, vector addition, subtraction, multiplication [scalar and vector]. Could you give me a reference to such module? NumPy has array (and matrix) types with support for these

RE: Vectors

2011-04-20 Thread Andreas Tawn
On Apr 20, 6:43 am, Andreas Tawn andreas.t...@ubisoft.com wrote: Algis Kabaila akaba...@pcug.org.au writes: Are there any modules for vector algebra (three dimensional vectors, vector addition, subtraction, multiplication [scalar and vector]. Could you give me a reference

RE: Remove all directories using wildcard

2011-03-18 Thread Andreas Tawn
I'm new to python and I am trying to figure out how to remove all sub directories from a parent directory using a wildcard. For example, remove all sub directory folders that contain the word PEMA from the parent directory C:\Data. I've trying to use os.walk with glob, but I'm not sure if

RE: Executing functions

2011-02-11 Thread Andreas Tawn
Can someone help me understand why Example #1 Example #2 will run the functions, while Example #3 DOES NOT? Thanks for your time! R.D. def One(): print running fuction 1 def Two(): print running fuction 2 def Three(): print running fuction 3 # Example #1 fList =

RE: frequency of values in a field

2011-02-09 Thread Andreas Tawn
How do you add all the records in the particular field of interest into long_list? From earlier in the thread you did... import arcgisscripting # Create the geoprocessor object gp = arcgisscripting.create() records_list = [] cur = gp.SearchCursor(dbfTable) row = cur.Next() while row: value

RE: Namespaces

2011-01-22 Thread Andreas Tawn
What is namespace? And what is built-in namespace? -- http://mail.python.org/mailman/listinfo/python-list http://lmgtfy.com/?q=python+namespace -- http://mail.python.org/mailman/listinfo/python-list

RE: str(int_var) formatted

2010-10-29 Thread Andreas Tawn
Hi all, i've to convert integer x to string, but if x 10, the string have to be '0x' instead of simple 'x' for example: x = 9 str(x) -- '09' x = 32 str(x) -- '32' x represent hour/minute/second. I can easily add '0' with a if then block, but is there a built-in way to add

RE: regex to remove lines made of only whitespace

2010-08-11 Thread Andreas Tawn
Hi All, I'm looking for a regex (or other solution, as long as it's quick!) that could be used to strip out lines made up entirely of whitespace. eg: 'x\n \t \n\ny' - 'x\ny' Does anyone have one handy? cheers, Chris for line in lines: if not line.strip(): continue

RE: regex to remove lines made of only whitespace

2010-08-11 Thread Andreas Tawn
On 08/11/10 06:21, Andreas Tawn wrote: I'm looking for a regex (or other solution, as long as it's quick!) that could be used to strip out lines made up entirely of whitespace. eg: 'x\n \t \n\ny' - 'x\ny' for line in lines: if not line.strip(): continue

RE: Multiline regex

2010-07-21 Thread Andreas Tawn
I'm trying to read in and parse an ascii type file that contains information that can span several lines. Example: createNode animCurveTU -n test:master_globalSmooth; setAttr .tan 9; setAttr -s 4 .ktv[0:3] 101 0 163 0 169 0 201 0; setAttr -s 4 .kit[3] 10; setAttr -s 4

RE: RE: Multiline regex

2010-07-21 Thread Andreas Tawn
I could make it that simple, but that is also incredibly slow and on a file with several million lines, it takes somewhere in the league of half an hour to grab all the data. I need this to grab data from many many file and return the data quickly. Brandon L. Harris That's surprising. I

RE: Multiline regex

2010-07-21 Thread Andreas Tawn
I could make it that simple, but that is also incredibly slow and on a file with several million lines, it takes somewhere in the league of half an hour to grab all the data. I need this to grab data from many many file and return the data quickly. Brandon L. Harris That's surprising. I

RE: gui doubt

2010-06-17 Thread Andreas Tawn
On 06/17/2010 01:04 AM, Stephen Hansen wrote: On 6/16/10 10:40 PM, madhuri vio wrote: if i want to create a button which performs the transcription of dna to rna using tkinter in a gui... can u give me the method... You can not possibly be serious. Oh, it's not that bad

RE: Need help in python plug-in development

2010-04-28 Thread Andreas Tawn
Hi, I am new to python. I am using python 2.6. I have gone through the basic python and now I am trying to develop some plugin for maya 2009 through python. So, for that I would need helping hand. You'll probably have more luck with pymel specific stuff at http://www.tech-artists.org/

RE: Sleep timer but still responsive?

2010-01-29 Thread Andreas Tawn
On Jan 28, 4:55 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: Please provide more details. What do you want your program to do while sleeping? What kind of actions do you want a response to? Do you have a GUI? A curses-based interfase? -- Gabriel Genellina My app is purely

RE: How to print without spaces?

2009-09-18 Thread Andreas Tawn
Hi, I don't want to print the space between 'a' and 'b'. Could somebody let me know how to do it? Regards, Peng $ python Python 2.5.2 (r252:60911, May 21 2008, 10:08:24) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type help, copyright, credits or license for more information.

RE: Extracting patterns after matching a regex

2009-09-08 Thread Andreas Tawn
Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had

RE: Extracting patterns after matching a regex

2009-09-08 Thread Andreas Tawn
Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to

RE: Extract the numeric and alphabetic part from an alphanumeric string

2009-08-03 Thread Andreas Tawn
Hi, I have a string as str='123ACTGAAC'. I need to extract the numeric part from the alphabetic part which I did using numer=re.findall(r'\d+',str) numer 123 To get the alphabetic part, I could do alpha=str.replace('123','') alpha ACTGAAC But when I give

RE: index nested lists

2009-07-28 Thread Andreas Tawn
hi at all, If I have this list: lista ['ciao', 1, ['mela', 'pera', 'banana'], [1, 2, 3]] if I want enumerate elements...I can see: for parola in lista: print lista[i] i = i + 1 ciao 1 ['mela', 'pera', 'banana'] [1, 2, 3] but, if I want to enumerate elements

RE: list of all possible values

2009-07-16 Thread Andreas Tawn
Certainly possible with list comprehensions. a = abc [(x, y) for x in a for y in a] [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('c', 'a'), ('c', 'b'), ('c', 'c')] But I like bearophile's version better. Andreas, Thanks, but I think you were

RE: list of all possible values

2009-07-14 Thread Andreas Tawn
David Gibb: For example: if my values are ['a', 'b', 'c'], then all possible lists of length 2 would be: aa, ab, ac, ba, bb, bc, ca, cb, cc. from itertools import product list(product(abc, repeat=2)) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('c', 'a'),

RE: Specific iterator in one line

2009-06-30 Thread Andreas Tawn
This is purely sport question. I don't really intend to use the answer in my code, but I am wondering, if such a feat could be done. I have a following problem: I have a list based upon which I would like to construct a different one. I could simply use list comprehensions, but there

RE: Specific iterator in one line

2009-06-30 Thread Andreas Tawn
This is purely sport question. I don't really intend to use the answer in my code, but I am wondering, if such a feat could be done. I have a following problem: I have a list based upon which I would like to construct a different one. I could simply use list comprehensions, but

RE: Specific iterator in one line

2009-06-30 Thread Andreas Tawn
Andreas Tawn andreas.t...@ubisoft.com writes: list(.join([(a,b*2)[x] for x in [1,0,0,1]]) 50 characters. Do I win £5? Er, missing right paren. Try: list(.join((a,bb)[x] for x in [1,0,0,1])) -- Indeed. Stupid paste ;o) -- http://mail.python.org/mailman/listinfo/python-list

RE: While Statement

2009-05-22 Thread Andreas Tawn
Im using 2.6 python and when running this class progess(): def __init__(self, number, total, char): percentage = float(number/total*100) percentage = int(round(percentage)) char = char * percentage print char progess(100, 999,

RE: Printing a hex character and prefixing it correctly

2009-05-15 Thread Andreas Tawn
If I have an integer k, for instance; k = 32 // BASE 10 How do I get print to print it out in HEX and PREFIXED with 0x? What is the PROPER WAY? This does not work: print This is hex 32: , int(k, 16) Xav k = 32 print This is hex 32: , hex(k) Cheers, Drea --

RE: Python to Perl transalators

2009-03-18 Thread Andreas Tawn
2009/3/17 abhinayaraj.r...@emulex.com: Could anyone suggest whether there is any Python to Perl code convertors? I found one on the net viz. Perthon. But it wasn't really helping out. I am just a beginner learning both the languages. Wondered if I can have some comparative

RE: Inverse of dict(zip(x,y))

2009-03-04 Thread Andreas Tawn
Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any trick to get lists x = [x1, x2, ...]

RE: Inverse of dict(zip(x,y))

2009-03-04 Thread Andreas Tawn
So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any trick to get lists x = [x1, x2, ...] and y = [y1, y2, ...] Cheers, Chaitanya. x = d.keys() y = d.values() But be aware that you

RE: python 3 error i know the file works in python 2.6

2009-02-05 Thread Andreas Tawn
#open file and read last names filename = input('name file') file = open(filename, 'r') names_list = file.readlines() file.close() #open a file for saving passwords outfile_name = input('Save passwords') outfile = open(outfile_name, 'a') #create a password for each name in list import random,

RE: is there a shorter way to write this

2009-01-29 Thread Andreas Tawn
I had a task in a book to pick 5 items from a list of 26 ensuring the items are not repeated import random list = ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'] word = ' ' a = random.choice(list) list.remove(a) b =

RE: Kicking off a python script using Windows Scheduled Task

2008-10-15 Thread Andreas Tawn
Does anyone know how to properly kick off a script using Windows Scheduled Task? The script calls other python modules within itself. HERE'S THE CATCH: I am used to running the script directly from the command window and the print() is very handy for us to debug and monitor. When running the

RE: Extracting hte font name from a TrueType font file

2008-09-18 Thread Andreas Tawn
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] g] On Behalf Of Steve Holden Sent: Thursday, September 18, 2008 5:59 PM To: python-list@python.org Subject: Extracting hte font name from a TrueType font file Does anyone have a Python recipe for this?

RE: Unable to lookup keys in dictionary

2008-08-12 Thread Andreas Tawn
I am trying to run p4python API on top of python 2.5.2 and am extracting a dictionary from perforce. The following code returns the output that follows it: from P4 import P4, P4Exception p4 = P4() p4.port = erased #deleted p4.user =

RE: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Andreas Tawn
Terry Reedy wrote: Wrong. Thank you. For loop variables continue after the loop exits. This is intentional. I never knew that and I can't find reference to it in the docs. Can you help me with the reasons for it? Drea -- http://mail.python.org/mailman/listinfo/python-list

RE: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Andreas Tawn
Andreas Tawn wrote: Terry Reedy wrote: Wrong. Thank you. For loop variables continue after the loop exits. This is intentional. I never knew that and I can't find reference to it in the docs. Interesting starting point. It never occurred to me that they might not. (So I

RE: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread Andreas Tawn
defn noob wrote: isPrime works when just calling a nbr but not when iterating on a list, why? adding x=1 makes it work though but why do I have to add it? Is there a cleaner way to do it? def isPrime(nbr): for x in range(2, nbr + 1): if nbr % x == 0: break

RE: boolian logic

2008-06-13 Thread Andreas Tawn
if a != b and a != c and a != d: doStuff() else: doOtherStuff() Cheers, Drea HI all, I'm a bit stuck with how to work out boolian logic. I'd like to say if A is not equal to B, C or D: do something. I've tried if not var == A or B or C: and various permutations but can't

RE: file open/read/name etc, not working

2008-05-15 Thread Andreas Tawn
import os print os.path.exists('C:/Python25/myPrograms/netflix/test.txt') d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r') d.readline() returns true in the shell but prints no text even though the document contains text. d.name returns nothing, d.name() raises an error. --

RE: exists=false, but no complaint when i open it!?

2008-05-15 Thread Andreas Tawn
print os.path.exists('C:\Users\saftarn\Desktop\NetFlixDataSet \training_set') returns False... i have thourogly checked the filename to be correct and if we assume it is what could this mean then? i had a problem one other time when i had renamed a file but windows didnt rename it compeltely

RE: First Program Bug (Newbie)

2008-03-19 Thread Andreas Tawn
[snip] What is the square root function in python? There's one in the math module. Use the one in gmpy if you have it. Or raise to the power 1/power 9**(1.0/2) 3.0 Also works for cube root, quad root etc. 27**(1.0/3) 3.0 81**(1.0/4) 3.0 243**(1.0/5) 3.0 Cheers, Drea --

RE: Web site for comparing languages syntax

2008-02-26 Thread Andreas Tawn
Sebastian Bassi wrote: I know there is one site with wikimedia software installed, that is made for comparing the syntax of several computer languages (Python included). But don't remember the URL. Anyone knows this site? http://99-bottles-of-beer.net/ is one such site, though I don't know

RE: Encryption Recommendation

2008-01-28 Thread Andreas Tawn
I'm still using Python 2.4. In my code, I want to encrypt a password and at another point decrypt it. What is the standard way of doing encryption in python? Is it the Pycrypto module? Usually, one doesn't store clear-text passwords. Instead, use a hash-algorithm like md5 or crypt (the

RE: Hexadecimal list conversion

2007-12-20 Thread Andreas Tawn
Hi All. I have a list which is a line from a file: ['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009 \x009\x00', '\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\ x002\x00'] This should be in the format: ['381475.502599', '213622.174282'] I've tried a few

RE: Timeout test hangs IDLE

2007-12-06 Thread Andreas Tawn
I once made a small app that used threads on IDLE. There was a strange error when using 'print' threads. When what I printed filled the entire screen, instead of moving all the text up, IDLE just hanged. Try running your code from the shell instead, to see if the problem is in IDLE.

RE: Timeout test hangs IDLE

2007-12-05 Thread Andreas Tawn
On Dec 5, 6:00 am, Andreas Tawn [EMAIL PROTECTED] wrote: I'm trying to integrate the timeout function from herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/47 3878into a long running automation script and the following code causes IDLE after 20 or 30 iterations in countTest

RE: Timeout test hangs IDLE

2007-12-05 Thread Andreas Tawn
On Dec 5, 6:00 am, Andreas Tawn [EMAIL PROTECTED] wrote: I'm trying to integrate the timeout function from herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/47 3878into a long running automation script and the following code causes IDLE after 20 or 30 iterations

Timeout test hangs IDLE

2007-12-05 Thread Andreas Tawn
I'm trying to integrate the timeout function from here http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473878 into a long running automation script and the following code causes IDLE after 20 or 30 iterations in countTest. This is in 2.5, XP and there's no traceback. Could someone point

RE: Last iteration?

2007-10-12 Thread Andreas Tawn
): if i == len(myList)-1: print j*j else: print j Cheers, Andreas Tawn Lead Technical Artist Ubisoft Reflections -- http://mail.python.org/mailman/listinfo/python-list

RE: Really basic problem

2007-10-08 Thread Andreas Tawn
have an exact representation as floating point. Interestingly: 0.10001 == 0.1 True 0.30004 == 0.3 False I guess this means that Python has some concept of close enough, but I'll have to defer to someone more knowledgeable to explain that. Cheers, Andreas Tawn Lead

RE: Really basic problem

2007-10-08 Thread Andreas Tawn
and a head-smack, I realise that you're absolutely right and I just made the same mistake as the OP (doh). It does demonstrate just how sneaky floating point representations are though. Cheers, Andreas Tawn Lead Technical Artist Ubisoft Reflections -- http://mail.python.org/mailman/listinfo/python

Re: generating range of numbers

2007-10-03 Thread Andreas Tawn
i just want to generate numbers in the form like: 1,2,4,8,16,32.to a maximum of 1024 using a range function a = [2**x for x in range(11)] a [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024] Cheers, Andreas Tawn Lead Technical Artist Ubisoft Reflections -- http://mail.python.org/mailman

Re: interesting puzzle......try this you will be rewarded...

2007-09-07 Thread Andreas Tawn
) Maybe http://www.pythonchallenge.com/ ? Cheers, Drea Andreas Tawn Lead Technical Artist Ubisoft Reflections -- http://mail.python.org/mailman/listinfo/python-list