string.atoi and string.atol broken?
I think there may be a bug in string.atoi and string.atol. Here's some output from idle. Python 2.3.4 (#2, Jan 5 2005, 08:24:51) [GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2 Type "copyright", "credits" or "license()" for more information. Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. IDLE 1.0.4 import string as s s.atoi('2',3) 2 s.atoi('4',3) Traceback (most recent call last): File "", line 1, in -toplevel- s.atoi('4',3) File "/usr/lib/python2.3/string.py", line 220, in atoi return _int(s, base) ValueError: invalid literal for int(): 4 s.atoi('12',11) 13 s.atoi('13',4) 7 s.atoi('12',4) 6 s.atoi('8',4) Traceback (most recent call last): File "", line 1, in -toplevel- s.atoi('8',4) File "/usr/lib/python2.3/string.py", line 220, in atoi return _int(s, base) ValueError: invalid literal for int(): 8 s.atoi('4',3) should result in 11 s.atoi('13',4) should result in 31 s.atoi('12',4) should result in 30 s.atoi('8',4) is legitimate, but it generates an error. Is this a bug, or am I missing something obvious? TIA, Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: string.atoi and string.atol broken?
Dennis Benzinger wrote: Just out of curiosty: What did you think what atoi does? I don't understand how you came to expect that atoi('4',3) should result in 11. Bye, Dennis Mea culpa. For some strange reason, I had it in my mind that atoi would take a base ten number as a string and convert it to the correct representation in the base of the second argument. In other words, atoi('4',3) should take 4 in base 10 and convert it to base 3, resulting in 11. Exactly backwords, as atoi('11',3) = 4, that is, 11 base 3 = 4 base 10. Thanks to all for setting me straight. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a dictionary from an object
Thanos Tsouanas wrote: I'm not sure what you're getting at, but have you tried this: class A(object): def __getitem__(self, ky): return self.__dict__[ky] for example: >>> class A(object): def __init__(self,a,b,c): self.a = a self.b = b self.c = c def __getitem__(self, ky): return self.__dict__[ky] >>> a = A(1,2,3) >>> a['a'] 1 >>> a['b'] 2 >>> > Hello. > > I would like to have a quick way to create dicts from object, so that a > call to foo['bar'] would return obj.bar. > > The following works, but I would prefer to use a built-in way if one > exists. Is there one? > > Thanks in advance. > > class dictobj(dict): > """ > class dictobj(dict): > A dictionary d with an object attached to it, > which treats d['foo'] as d.obj.foo. > """ > def __init__(self, obj): > self.obj = obj > def __getitem__(self, key): > return self.obj.__getattribute__(key) > -- http://mail.python.org/mailman/listinfo/python-list
Installing Python on a Windows 2000 Server
Hi, I'm a civil engineer who also doubles as chief programmer for technical applications at my company. Most of our software is written in Visual Basic because our VP in charge of I.T. likes to have "consistency", and at the moment we're a Microsoft shop. He has assigned me the task of developing an new application, the exact nature of which is not important for my question. I told him that, in my opinion, that Visual Basic was not the best choice for developing this application, and that I wanted to use Python. After a bit of discussion of the pros and cons, he said to go ahead. I managed to keep my jaw from hitting the floor. :>) We have a central server array running Windows Server 2000 (I think that's the right name; networking is not my specialty, but it's definately Windows). Some of our workstations run Windows 2000; others run Windows XP Pro. I would like to install Python on the server, and run the application that I'll be developing from the workstations, without having to install any Python components on the workstations themselves. In other words, the Python executable, and the various libraries, dll's, and what have you, as well as the application that I'm developing, should all reside on the server. The only thing on the workstations would be a shortcut to myapplication.py. Does anyone know whether it is possible to do this? I've done some Google searching, with no conclusive results, and poked about on python.org, but haven't really been able to find anything. Normally I'd be happy to just try it out and see what happens, but we're breaking new ground here (this is an amazingly big step for our hide-bound IS department!), so I'd like everything to go as smoothly as possible. TIA, Mike -- http://mail.python.org/mailman/listinfo/python-list