Re: "finding hostid with python"

2007-12-07 Thread kdwyer
On Dec 7, 9:10 pm, farsheed <[EMAIL PROTECTED]> wrote:
> I,m searching  for a way to obtain hostid in windows.
> Any ideas?


IIRC, MArk Hammond's extensions for windows have a method for
obtaining the fully qualified hostname of a machine.

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


Re: Naive idiom questions

2008-02-02 Thread kdwyer
On Jan 31, 9:30 pm, Terran Melconian
<[EMAIL PROTECTED]> wrote:
>
> I want to be able to accumulate a string with +=, not by going
> through an intermediate list and then doing ''.join(), because I
> think the latter is ugly.

As others have observed, you can build a string using += instead of
''.join(), but += runs in quadratic time so it's not terribly
efficient if you're building strings out of a lot of elements, or if
the number of elements is arbitrary.

Cheers,

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


Re: Broke my IDLE!

2008-02-05 Thread kdwyer
On Feb 5, 5:05 pm, "Adam W." <[EMAIL PROTECTED]> wrote:
> Tried running IDEL from the command prompt to get this:
>
> Traceback (most recent call last):
>   File "c:\Python25\Lib\idlelib\idle.pyw", line 21, in 
> idlelib.PyShell.main()
>   File "c:\Python25\lib\idlelib\PyShell.py", line 1404, in main
> shell = flist.open_shell()
>   File "c:\Python25\lib\idlelib\PyShell.py", line 275, in open_shell
> self.pyshell = PyShell(self)
>   File "c:\Python25\lib\idlelib\PyShell.py", line 813, in __init__
> OutputWindow.__init__(self, flist, None, None)
>   File "c:\Python25\lib\idlelib\OutputWindow.py", line 16, in __init__
> EditorWindow.__init__(self, *args)
>   File "c:\Python25\lib\idlelib\EditorWindow.py", line 125, in
> __init__
> self.apply_bindings()
>   File "c:\Python25\lib\idlelib\EditorWindow.py", line 900, in
> apply_bindings
> text.event_add(event, *keylist)
>   File "c:\Python25\lib\idlelib\MultiCall.py", line 345, in event_add
> widget.event_add(self, virtual, seq)
>   File "c:\Python25\lib\lib-tk\Tkinter.py", line 1357, in event_add
> self.tk.call(args)
> _tkinter.TclError: extra characters after detail in binding
>
> What do I need to edit and change?

IIRC IDLE leaves some config files lying around in whatever was the
current directory when it was executed.  I think they're named idle.rc
but I don't have a working install around to check on.  It's possible
that you need to clear these out to remove the binding.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Broke my IDLE!

2008-02-06 Thread kdwyer
Just to clarify my earlier comment...

IDLE (on Windows, at least) creates a folder called .idlerc in the
current directory when it is called.  If you amend the key bindings
two files, config-keys.cfg and config-main.cfg are created.  config-
keys.cfg contains the amended key bindings and config-main.cfg
contains the name of the key binding file if it is not the platform
default.

The config processing seems to happen in /Lib/idlelib/
configHandler.py.

Sorry for the inaccuracy in the first post,

Cheers,

Kev

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


Re: Possible read()/readline() bug?

2008-10-22 Thread kdwyer
On 22 Oct, 19:54, Mike Kent <[EMAIL PROTECTED]> wrote:
> Before I file a bug report against Python 2.5.2, I want to run this by
> the newsgroup to make sure I'm not being stupid.
>
> I have a text file of fixed-length records I want to read in random
> order.  That file is being changed in real-time by another process,
> and my process want to see the changes to the file.  What I'm seeing
> is that, once I've opened the file and read a record, all subsequent
> seeks to and reads of that same record will return the same data as
> the first read of the record, so long as I don't close and reopen the
> file.  This indicates some sort of buffering and caching is going on.
>
> Consider the following:
>
> $ echo "hi" >foo.txt  # Create my test file
> $ python2.5  # Run Python
> Python 2.5.2 (r252:60911, Sep 22 2008, 16:13:07)
> [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> f = open('foo.txt')  # Open my test file
> >>> f.seek(0)# Seek to the beginning of the file
> >>> f.readline() # Read the line, I get the data I expected
> 'hi\n'
> >>> # At this point, in another shell I execute 'echo "bye" >foo.txt'.  
> >>> 'foo.txt' now has been changed
> >>> # on the disk, and now contains 'bye\n'.
> >>> f.seek(0)# Seek to the beginning of the still-open file
> >>> f.readline() # Read the line, I don't get 'bye\n', I get the 
> >>> original data, which is no longer there.
> 'hi\n'
> >>> f.close() # Now I close the file...
> >>> f = open('foo.txt') # ... and reopen it
> >>> f.seek(0)   # Seek to the beginning of the file
> >>> f.readline()# Read the line, I get the expected 'bye\n'
> 'bye\n'
>
> It seems pretty clear to me that this is wrong.  If there is any
> caching going on, it should clearly be discarded if I do a seek.  Note
> that it's not just readline() that's returning me the wrong, cached
> data, as I've also tried this with read(), and I get the same
> results.  It's not acceptable that I have to close and reopen the file
> before every read when I'm doing random record access.
>
> So, is this a bug, or am I being stupid?

Hello Mike,

I'm guessing that this is not a bug.  I'm no expert, but I'd guess
that the open(file, mode) function simply loads the file into memory,
and that further operations (such as seek or read) are performed on
the in-memory data rather than the data on disk.  Thus changes to the
file are only observed after a fresh open operation.

This behaviour is probably enforced by the C library on the machine
that you are using.  If you want to be able to pick up data changes
like this then you're better off using a database package that has
support for concurrent access, locking and transactions.

Cheers,

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


Re: problem with dictionaries

2008-04-23 Thread kdwyer
On Apr 23, 12:16 pm, Simon Strobl <[EMAIL PROTECTED]> wrote:
> Hello,
>
> the idea of the following program is to parse a frequency list of the
> form FREQUENCY|WORD, to store the frequency of a word in a dictionary
> (and to do some things with this information later).
>
> I have done this many many times. Suddenly, it does not work any more:
> The value frq[key] is different from the value that key has in the
> file 'my_frqlist.txt'.
>
> I am using Python 2.5.1
>
> Any hints?
>
> Simon
>
> 
>
> #!/usr/bin/python
>
> import sys
>
> frqlist = open('my_frqlist.txt', 'r')
>
> # my_frqlist looks like this:
> # 787560608|the
> # 434879575|of
> # 413442185|and
> # 395209748|to
> # 284833918|a
> # 249111541|in
> # 169988976|is
>
> frq = {}
>
> for line in frqlist:
> line = line.rstrip()
> frequency, word = line.split('|')
> frq[word] = int(frequency)
>
> for key in frq.keys():
> print key,  frq[key]

It works for me, save that you need to read the file into a list first
- is this really the code that you are running?  What results are you
getting?

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


Re: problem with dictionaries

2008-04-23 Thread kdwyer
On Apr 23, 1:22 pm, Bruno Desthuilliers  wrote:
> kdwyer a écrit :> On Apr 23, 12:16 pm, Simon Strobl <[EMAIL PROTECTED]> wrote:
> (snip)
> >> #!/usr/bin/python
>
> >> import sys
>
> >> frqlist = open('my_frqlist.txt', 'r')
> (snip)
> >> frq = {}
>
> >> for line in frqlist:
> >> line = line.rstrip()
> >> frequency, word = line.split('|')
> >> frq[word] = int(frequency)
>
> (snip)
>
> > It works for me, save that you need to read the file into a list first
>
> You don't, unless you're using an old python versions (I'd say 2.3 or
> older). Files are now their own iterators.

*Fiddles with the interpreter for a moment*
So they are - I'd quite forgotten about that - thanks for the
reminder!

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


PyXml

2008-05-09 Thread kdwyer
Hello Everyone,

I've been looking into writing a utility to compare/analyse xml files, and
thought I'd have a look at PyXml, but the Sourceforge page says it's no
longer maintained.

Two questions:
What's the story with PyXml?  Is it stable/complete or has effort moved
elsewhere?

Can anyone recommend a Python validating parser that validates vs Xml
Schema?

Many thanks,

Kev

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


Re: PyXml

2008-05-10 Thread kdwyer
Stefan Behnel wrote:

> Martin v. Löwis wrote:
>>> Can anyone recommend a Python validating parser that validates vs Xml
>>> Schema?
>> 
>> The libxml bindings for Python can do that.
> 
> ... although the OP will likely prefer using lxml, where it's three lines
> of Python (ok, plus an import), compared to quite a bit of code in the
> official libxml2 bindings.
> 
> http://codespeak.net/lxml
> 
> Stefan
> --
> http://mail.python.org/mailman/listinfo/python-list

Stefan, Martin,

Thanks for your replies.

Kev

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

Re: How can this script fail?

2008-08-27 Thread kdwyer
On 27 Aug, 12:15, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> On Aug 27, 1:08 pm, "M.-A. Lemburg" <[EMAIL PROTECTED]> wrote:
>
> > I don't think this is related to IDLE or your setup. The odbc
> > module is very old and unmaintained, so it's possible that Windows
> > doesn't find some system DLLs needed for it to work.
>
> Please note that
> 1) I can type "import odbc" directly into the IDLE shell without
> getting an error message,
> but only BEFORE I've run a script that tries to import odbc.
> 2) The same script runs fine under PyWin (which I don't like much as
> an environment).
>
> > If you're looking for a reliable Python ODBC interface, I'd suggest
> > you have a look at our mxODBC:
>
> Thanks, but I'm working on some kind of guerilla project of which my
> employer doesn't know, so they won't spend any money on a commercial
> product.
>
> robert

Hello,

Your script works fine for me on my machine (Python 2.5.2, IDLE 1.2.2,
WinXP).

The two directories returned in the 'found in path' section are a
result of the .lower() method being called on the directory names in
the if statement.

So it looks to me as if IDLE/Python is not necessarily the problem.  I
notice that if I run a script from IDLE using F5 (this is what you're
doing, right?) the directory that contains the script is inserted at
the begining of sys.path.  Is there anything unusual in this
directory, particularly objects called 'odbc'?

Cheers,

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