> 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
> 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.
--
http://mail.python.org/mailman/listinfo/py
> >> 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.
--
http://mail.py
> > 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.
--
http://mail.python.org/m
> 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
> 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 objec
> On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn
> 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 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 f
> 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
> 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
> 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!
>
>
> On Apr 20, 6:43 am, Andreas Tawn wrote:
> > > Algis Kabaila writes:
> >
> > > > Are there any modules for vector algebra (three dimensional
> > > > vectors, vector addition, subtraction, multiplication [scalar
> > > > and vector]. Could y
> Algis Kabaila 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 basic
> operati
> 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
> 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"
>
>
> # Ex
> 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:
valu
> 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
> 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
> 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
> 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():
>>> 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
>>>
>> T
> 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'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;
>
> 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 no
> 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/
Chee
> On Jan 28, 4:55 pm, "Gabriel Genellina"
> 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 cons
> 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
> > > 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 approa
> 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
> 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 giv
> 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
> > 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,
>
> Tha
> 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',
> '
erator in one line
>
> "Andreas Tawn" 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
> > > 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
> > > comp
> > 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,
> 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(1
> 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
--
ht
> > 2009/3/17 :
> >> 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 understanding of both.
>>>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()
>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, ..
>#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
> 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
> 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
> -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?
>
>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.us
> 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.
>
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
>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:
>>
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 bu
>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 compeltel
>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.
>--
>http
[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
-
>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
>> 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 (
> 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 tr
> 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 IDL
> > 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 scri
> 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
&
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 m
gt; 9
Something like:
myList = [1, 2, 3]
for i, j in enumerate(myList):
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
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>
After some caffeine 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.
Chee
t;>> 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 Technical Artist
Ubisoft Reflections
--
http://mail.python.org/mailman/listinfo/python-list
>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 Reflectio
yet so I can't vouch for its quality. (am playing
>it now)
Maybe http://www.pythonchallenge.com/ ?
Cheers,
Drea
Andreas Tawn
Lead Technical Artist
Ubisoft Reflections
--
http://mail.python.org/mailman/listinfo/python-list
65 matches
Mail list logo