Re: which reg values modified my python installer under windows

2005-09-06 Thread keirr
Philippe,

You wrote:  I wish to associate *.pyc with pythonw.exe

  is there some reason why Tools->Folder Options->File Types (from a
Windows Explorer menu) won't work?

You could do it from a cmd prompt with assoc and ftype if you needed to
script it.

All the best,

 Keir.

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


Re: which reg values modified my python installer under windows

2005-09-06 Thread keirr
Philippe,

Windows file associations are in
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts

Hope that helps you.

 All the best,

Keir.

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


Re: Strings

2005-04-21 Thread keirr
I'd use the int and chr casts.  e.g.,

new_string = ""
a = '012'
new_string += chr(int(a))

Just in case the 012 is an octal code I'll mention that to cast to int
in general you can pass the base, as in int('034',8) or int('AF',16)

Cheers,

 Keir.

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


Re: UDP socket, need help setting sending port

2005-12-20 Thread keirr
Fred,

   It is quite possible I've misunderstood the problem :-)  but have
you tried anything like

   import socket
   tc_local_port =  
   tc_remote_port = 
   outgoing_if = "172.16.1.2"  # say
   remote_tc_host = "172.16.1.3" # say
   # udp is the default for DGRAM
   tc_sock = socket(socket.AF_INET, socket.SOCK_DGRAM)
   tc_sock.bind((outgoing_if, tc_local_port))
   tc_sock.connect((remote_tc_host, tc_remote_port))

   If you send data with tc_sock, it should have a source port of
tc_local_port.
   So, to set the source port, call bind.  You should do that before
calling connect, since
   calling connect on an unbound socket has the side effect of
assigning an ephemeral port to the socket.
   Hope that was of some help to you.

All the best,

 Keir.

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


Re: UDP socket, need help setting sending port

2005-12-20 Thread keirr
A few trivial corrections, to my own post :-(
tc_sock = socket(socket...
should be
tc_sock = socket.socket(socket...
of course

 and, (while I'm here)  when I stated that calling connect on an
unbound socket caused
a ephemeral port to be assigned, I should have written "calling connect
on an unbound _UDP_ socket, etc. "

Cheers,

 Keir.

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


Re: Creating interactive command-line Python app?

2005-12-21 Thread keirr
You may also find the cmd module useful, see:
http://docs.python.org/lib/module-cmd.html

Cheers,

 Keir.

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


Re: Is it possible to use python to unit test C++ code?

2005-12-21 Thread keirr
[EMAIL PROTECTED] wrote:
> Is it possible to use python to unit test C++ code? If yes, is there
> any example available?
>

If I had to use python to test C++ code, I'd use the Boost python
library: http://www.boost.org/libs/python/doc/ to expose my C++
classes, and write the unittests in python after importing the wrapped
C++ code.
Note, you did ask if it was possible.  Is it advisable?  That's another
question.

All the best,

 Keir.

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


Re: Providing 'default' value with raw_input()?

2005-12-22 Thread keirr
planetthoughtful wrote:
> I'm wondering if it's possible, using raw_input(), to provide a
> 'default' value with the prompt?
>
def get_input_with_default(default, prompt=">>> "):
result = raw_input('['+str(default)+'] '+str(prompt))
if result == "": result = default
return default

> I would like to include the ability to edit an existing value (drawn
> from an SQLite table) using a DOS console Python app, but my gut
> feeling from reading what I can find about raw_input() is that it only
> allows you to provide a prompt, not a default value as well.
>
I think it is the editing part that is going to give you a hard time.
curses and readline might be some help if you were on a Unix platform.
I can't think of any way to provided a editable  value at the dos
prompt.  

All the best,
 Keir.

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


Re: Providing 'default' value with raw_input()?

2005-12-22 Thread keirr
planetthoughtful wrote:

> It seems, according to keir, that this simply can't be done via the
> command line in DOS, which is a shame.

Now, I said I couldn't think of a way to do it - not that it wasn't
possible :-)
If you don't need you program to be portable you can use extensions -
in this case
I would expect you need readline for windows, and ctypes (because
readline for windows needs ctypes).

You can fetch readline from
http://sourceforge.net/project/showfiles.php?group_id=82407
and ctypes from
http://sourceforge.net/project/showfiles.php?group_id=71702

I can't promise these will work (all my python has to be 'pure' and
cross platform so I've never used readline or rlcompleter) but
functions like insert_text look to be in the right area for what (I
think) you want. 
Good luck!

Keir.

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


Re: jython: True and False boolean literals?

2005-12-22 Thread keirr
[EMAIL PROTECTED] wrote:
> Aren't there boolean literals for "True" and "False" in Python

>>> True != False
True
>>> type(True)


works for most people :-)

All the best,

 Keir

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


Re: jython: True and False boolean literals?

2005-12-22 Thread keirr

keirr wrote:
> [EMAIL PROTECTED] wrote:
> > Aren't there boolean literals for "True" and "False" in Python
>
> >>> True != False
> True
> >>> type(True)
> 
>
> works for most people :-)
>
Ahem, who use python. For jython this looks like
>>> True != False
1
>>> type(True)


Keir.

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


Re: jython: True and False boolean literals?

2005-12-22 Thread keirr
Kent Johnson wrote:
> [EMAIL PROTECTED] wrote:
> > Aren't there boolean literals for "True" and "False" in Python
> > (jython)?  I can't get "true", "True", "false", or "False" to work.  I
> > ended up having to use "(1==1)" and "(1==0)".
>
> No, there are not. Jython implements Python 2.1 which did not have boolean 
> literals. You
> can just use 1 and 0.
>
The latest jython is 2.2a1 (which does have True and False as ints)

You could declare your own True and False like this:
class Boolean:
__init__(self, value):
self.__value = value
__repr__(self):
return self.__value != 0
__int__(self):
return int(self.__value)
and so on.

then, True = Boolean(1)
and False = Boolean(0)

Cheers,
 Keir

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


Re: Providing 'default' value with raw_input()?

2005-12-22 Thread keirr
planetthoughtful wrote:
> Hi Kier,
>
> Any idea where I'd find documentation on using this extension? I've
> downloaded and installed, but haven't had any luck finding docs for it.
>
As it's a windows version of the standard readline module (usually
available on Unix only)
I'd _guess_ that you could use the standard library readline
documenation, i.e. go to python.org and look up the readline module in
the library docs.

Cheers,

 Keir.

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


Re: dictionary of list from a file

2006-10-04 Thread keirr
[EMAIL PROTECTED] wrote:

> in python I tried:
> b={}
> a=[]
> for line in fl.readlines():
>  info=lines.split()
>  b[info[0]] = a.append(info[1])
>
> and then
> for i in b:
>  print i,b[i]
> i get
> 2 None
> 7 None
>
> data file is:
> 2 1
> 2 2
> 2 3
> 2 4
> 7 7
> 7 8
> 7 9
> 7 10
>
> Any help??
Andrea,
 first the append method returns None, as you have discovered; it makes
an inplace update (to a in your example) but does not return the list
it has updated.   This has surprised a few people in the past :-)
Here is what I've used before for updating lists values in a
dictionary.

d[key] = d.get(key, []) + [value]

where d is a dict(ionary)

Hope this helps.

 Keir.

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


Re: Is Python suitable for a huge, enterprise size app?

2005-05-18 Thread keirr
> So, given the very general requirements in the first paragraph, do
you
> think that Python could handle it?  If anyone has direct experience
> developing large apps in Python, I would appreciate your insight.


I wouldn't, especially[1] if your thousands of business objects get
allocated/deallocated as the system runs.  Currently python's memory
usage can grow rapidly (from the perspective of the o/s) when large
numbers of objects are repeatedly created and freed.

On the other hand, you could use a combination of python and C++
(perhaps using boost's python wrapping code).  The ability to create
C/C++ modules is a "get out of jail free card" - if you did manage to
convince your company to go with python, and it fell short in some
area, a custom C module could be a handy trick.

Perhaps you could compare your project to existing large python
projects; like Zope maybe?

[1] if the objects in the system are static, rather than dynamic, of
course this is not an issue.  My "I wouldn't" comes from the fact that
your requirements include "lots of object" as a feature, and no word on
how they will be used. 

Good luck anyway :-)
 Keir.

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


Re: Is Python suitable for a huge, enterprise size app?

2005-05-18 Thread keirr
>> I wouldn't, especially[1] if your thousands of business objects get
>> allocated/deallocated as the system runs.  Currently python's memory
>> usage can grow rapidly (from the perspective of the o/s) when large
>> numbers of objects are repeatedly created and freed.

>Isn't it true that in recent Python releases, one may replace the
>default GC with custom one?

Good point.  Indeed, since you have the source code you can change
anything you like. My warning was aimed at a specific situation,  and
was meant to be a 'keep this in mind' comment (I phrased it as "don't
use python" really because I expected the majority of the responses to
be "do use python", and thought a bit of balance would be helpful).

 As for a custom garbage collector, there has been a little discussion
about the gc code (on this group). My feeling is, if it was easy to
make it better someone would have done it already.  Note I don't say
it's impossible (particularly with the resources the op mentioned),
just not straight-forward.

Of course, I wouldn't use Java, but that's another story '-)

Cheers,

 Keir.

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


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread keirr
On Feb 22, 5:43 pm, "John" <[EMAIL PROTECTED]> wrote:
> Is there any built in function that converts ASCII to integer or vice versa
> in Python?
>
> Thanks!

Try int.
ie.

try:
   int_val = int(str_val)
except ValueError:
   # conversion failed

Keir.

--
Keir Robinson
Sometimes a scream is better than a thesis. (Emerson)


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


Re: This coding style bad practise?

2006-05-03 Thread keirr

Martin P. Hellwig wrote:
> Hi all,
>
> I created a class which creates a relative unique id string, now my
> program just works fine and as expected but somehow I get the feeling
> that I misused the __repr__ since I guess people expect to 'execute' a
> function in an instance instead of using it's representation string of
> the instance itself, could you elaborate whether you find this bad
> practice and if yes what would have been a better way to do it?
>
> TIA
>

Rather than comment on the style of using a class, I'll just suggest an
alternative.
You can use a generator function, which yields the next id when called;
at least that's 
how I'd implement an IDgenerator.

Cheers,

 Keir.

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


Re: Modify one character in a string

2006-05-25 Thread keirr

mp wrote:
> X-No-Archive
> How do I go about modifying one character in a string elegantly?
> In other words, I want a function that will change '' to 'aaza',
> given the index 2 of the character in the string.
>
> Also, how do I do this when dealing with a file ; which file mode
> should I use and what function should I use to modify a single
> character once in that file mode?
>
> Thanks
> MP

Technically you can't - strings are immutable.  If you use the StringIO
module then you can
use a common approach between 'strings' in memory, and files, using
seek and write.

All the best,

 Keir.

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


Re: newbie questions

2006-03-15 Thread keirr

meeper34 wrote:
> Hi,
>
> I'm just starting out with Python, and so far I am thoroughly impressed
> with what you can do very easily with the language.  I'm coming from a
> C++ background here.  A couple of questions came up as I was thinking
> about dynamically typed languages:
>
> 1.  If someone releases an interface in Python, how does the user know
> what parameters the function takes/returns?
>
> 2.  If documentation is the answer to 1, then are there any Python
> documentation standards?
>
> 3.  Are there any tools out there that can extract the interface
> information from Python files and release it as documentation like
> header (.h) files?  I know there are tools like this for languages like
> C#.
>

epydoc: http://epydoc.sourceforge.net/ is used by a  bunch of people -
including me.
The documentation it produces is far from a header file, typically it
is in HTML
(although other output formats are available) but I find it does.

> 4.  Really basic question, and I'm sure I will learn this very quickly
> with more reading, but I'm confused by the lack of an entry point in a
> Python app, i.e. int main().

There is some idiom for this.

def main(*args, **kw):
# do stuff
pass
if __name__ == '__main__':
# call main, perhaps with sys.argv
main()

You put this at the bottom of the file you want to run.
The __name__ property will be '__main__' iff you have executed the file

from the command line.
In particular the code in the if __name__... block won't be run if you
just import the file.

All the best,

 Keir.

> Btw, I was turned on to Python from Bruce Eckel's article "Strong
> Typing vs Strong Testing."
> 
> Thanks,
> John

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