Re: Recursive Property of Octal Numbers

2005-10-01 Thread PoD
On Fri, 30 Sep 2005 15:40:51 -0700, James Stroud wrote:

> I'm very curious about what is going on here. I'm sure my curiosity has 
> something to do with ignorance of some fundamental concept of computer 
> science (maybe that 8 is just a vertical infinity?):
> 
> py> b = '\xb6'
> py> b[0]
> '\xb6'
> py> b[0][0]
> '\xb6'
> py> b[0][0][0]
> '\xb6'
> py> b[0][0][0][0]
> '\xb6'
> py> b[0][0][0][0][0]
> '\xb6'
> 
> 
> 
> James

b is a 1 character string.
b[0] is a one character string which is the first character of b.
Therefore b[0] == b.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Loop through a dict changing keys

2011-10-15 Thread PoD
On Sat, 15 Oct 2011 11:00:17 -0700, Gnarlodious wrote:

> What is the best way (Python 3) to loop through dict keys, examine the
> string, change them if needed, and save the changes to the same dict?
> 
> So for input like this:
> {'Mobile': 'string', 'context': '', 'order': '7',
> 'time': 'True'}
> 
> I want to booleanize 'True', turn '7' into an integer, escape
> '', and ignore 'string'.
> 
> Any elegant Python way to do this?
> 
> -- Gnarlie

How about

data = {
'Mobile': 'string',
'context': '',
'order': '7',
'time': 'True'}
types={'Mobile':str,'context':str,'order':int,'time':bool}

for k,v in data.items():
data[k] = types[k](v)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Loop through a dict changing keys

2011-10-17 Thread PoD
On Sun, 16 Oct 2011 00:18:40 -0700, Jon Clements wrote:

> On Oct 16, 12:53 am, PoD  wrote:
>> On Sat, 15 Oct 2011 11:00:17 -0700, Gnarlodious wrote:
>> > What is the best way (Python 3) to loop through dict keys, examine
>> > the string, change them if needed, and save the changes to the same
>> > dict?
>>
>> > So for input like this:
>> > {'Mobile': 'string', 'context': '', 'order': '7',
>> > 'time': 'True'}
>>
>> > I want to booleanize 'True', turn '7' into an integer, escape
>> > '', and ignore 'string'.
>>
>> > Any elegant Python way to do this?
>>
>> > -- Gnarlie
>>
>> How about
>>
>> data = {
>>     'Mobile': 'string',
>>     'context': '',
>>     'order': '7',
>>     'time': 'True'}
>> types={'Mobile':str,'context':str,'order':int,'time':bool}
>>
>> for k,v in data.items():
>>     data[k] = types[k](v)
> 
> Bit of nit-picking, but:
> 
>>>> bool('True')
> True
>>>> bool('False')
> True
>>>> bool('')
> False

Oops :) Brain fade.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getopt and options with multiple arguments

2005-12-19 Thread PoD
On Mon, 19 Dec 2005 02:29:41 -0800, [EMAIL PROTECTED] wrote:

> I want to be able to do something like:
> 
> myscript.py * -o outputfile
> 
> and then have the shell expand the * as usual, perhaps to hundreds of
> filenames. But as far as I can see, getopt can only get one argument
> with each option. In the above case, there isn't even an option string
> before the *, but even if there was, I don't know how to get getopt to
> give me all the expanded filenames in an option.
> 
> Help! :)
> 
> /David

The convention is to put options first and then any other stuff such as
filenames:-
myscript.py -o outputfile *

In this case getopt will return the options as one list and the rest as
another list.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function with variable arguments

2005-05-13 Thread PoD
On Fri, 13 May 2005 02:52:34 -0700, Xah Lee wrote:

> i wanted to define a function where the number of argument matters.
> Example:
> 
> def Range(n):
> return range(n+1)
> 
> def Range(n,m):
> return range(n,m+1)
> 
> def Range(n,m,step):
> return range(n,m+1,step)
> 
> this obvious doesn't work. The default argument like
> Range(n=1,m,step=1) obviously isn't a solution.
> 
> can this be done in Python?
> 
> or, must the args be changed to a list?
> 

def Range(n,m=None,step=1):
  if m is None:
n,m = 0,n+1
  else:
n,m = n,m+1
  return range(n,m,step)


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-18 Thread PoD
On Wed, 17 May 2006 21:37:14 +0800, Andy Sy wrote:

> If tabs are easily misunderstood, then they are a MISfeature
> and they need to be removed.
> 
>>From the Zen of Python:
> 
> "Explicit is better than implicit..."
> "In the face of ambiguity, refuse the temptation to guess..."
> "Special cases aren't special enough to break the rules..."

Exactly.
How many levels of indentation does 12 spaces indicate?
It could be 1,2,3,4,6 or 12.  If you say it's 3 then you are _implying_
that each level is represented by 4 spaces.

How many levels of indentation is 3 tabs?  3 levels in any code that you
will find in the wild.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-18 Thread PoD
On Thu, 18 May 2006 08:30:03 +, Duncan Booth wrote:

> PoD wrote:
>> How many levels of indentation does 12 spaces indicate?
>> It could be 1,2,3,4,6 or 12.  If you say it's 3 then you are
>> _implying_ that each level is represented by 4 spaces.
> 
> By reading the code I can see how many levels of indentation it
> represents. 
> 
>> How many levels of indentation is 3 tabs?  3 levels in any code that
>> you will find in the wild.
> 
> No. That is precisely the problem: there is code in the wild which
> contains mixed space and tab indentation, and any time that happens 3
> tabs could mean any number of indentations. 

I think it is universally accepted that mixed tabs and spaces is indeed
**EVIL**

I should have said any code using tabs exclusively.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-18 Thread PoD
On Thu, 18 May 2006 10:33:58 +0200, Christophe wrote:

> PoD a écrit :
>> On Wed, 17 May 2006 21:37:14 +0800, Andy Sy wrote:
>> 
>> 
>>>If tabs are easily misunderstood, then they are a MISfeature
>>>and they need to be removed.
>>>
>>>>From the Zen of Python:
>>>
>>>"Explicit is better than implicit..."
>>>"In the face of ambiguity, refuse the temptation to guess..."
>>>"Special cases aren't special enough to break the rules..."
>> 
>> 
>> Exactly.
>> How many levels of indentation does 12 spaces indicate?
>> It could be 1,2,3,4,6 or 12.  If you say it's 3 then you are _implying_
>> that each level is represented by 4 spaces.
> 
> Actually, who said you had to always use the same number of spaces to 
> indent ? 12 = 6 + 6 = 4 + 4 + 4 but also 12 = 2 + 10 = 1 + 1 + 3 + 3 + 4 :D

Thus supporting my assertion that space indenting is implicit not
explicit. Spaces are evil.

> 
>> How many levels of indentation is 3 tabs?  3 levels in any code that
>> you will find in the wild.
> 
> No, it could be 3 levels or 3 tabs per level or 2 tabs for the first
> level and 1 tab for the second ...

Could be but wouldn't be.

Maybe what Python should do (but never will given the obsession with using
spaces) is only allow one level of indentation increase per block so that

def foo():
return 'bar'

would return a syntax error

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs are *MISUNDERSTOOD*, *EVIL* AND *STUPID*, end of discussion. (Re: Tabs versus Spaces in Source Code)

2006-05-19 Thread PoD
On Fri, 19 May 2006 10:04:15 +0200, Christophe wrote:

> PoD a écrit :
>> Maybe what Python should do (but never will given the obsession with using
>> spaces) is only allow one level of indentation increase per block so that
>> 
>> def foo():
>> return 'bar'
>> 
>> would return a syntax error
> 
> Which would make  mandatory for indentation. What about some 
> freedom of choice ?

Hey, if people are allowed to say that tabs should be banned, then I'm
allowed to say they should be mandatory ;)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CAD file format specifications?

2009-06-19 Thread PoD
On Thu, 18 Jun 2009 13:39:28 +0200, Anthra Norell wrote:

>  I had a look at Blender. It looks impressive too. It might be an
> alternative to Sketch Up. I'll worry about that later. My immediate need
> is a file conversion utility. A cursory inspection of Blender's menu
> tabs and the various help options didn't turn up a file-conversion
> utility. So, my question is: How do I convert a bunch of
> three-dimensional coordinates defining lines into a file format Sketch
> Up can read (skp, dwg, dxf, 3ds, ddf or dem)?
> 
> Frederic

If you look in the File/Import menu in Blender, you will see all the file 
types which it can load.

The importing is done with python scripts, so if you are going to write a 
converter you might just as well write an import script for Blender.

The raw import script shows how simple it can be.

-- 
http://mail.python.org/mailman/listinfo/python-list