[issue13405] Add DTrace probes

2013-10-18 Thread Martin Marcher

Changes by Martin Marcher mar...@marcher.name:


--
nosy:  -serverhorror

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13405
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12360] Doc Typo

2011-06-18 Thread Martin Marcher

New submission from Martin Marcher mar...@marcher.name:

Slight typo in the docs.

I don't quite know how to work with mercurial. Hope it'll just work to merge 
the bitbucket link.

Typo is here: 
http://docs.python.org/py3k/library/asyncore.html#asyncore.dispatcher.handle_accepted
 (but also present in tip)

The parameter is named *sock*, but the docs talk about *conn*.

regards
Martin


hg diff -r 9569d8c4c781
diff -r 9569d8c4c781 Doc/library/asyncore.rst
--- a/Doc/library/asyncore.rst  Sat Jun 18 13:02:42 2011 -0400
+++ b/Doc/library/asyncore.rst  Sat Jun 18 22:08:42 2011 +0200
@@ -157,7 +157,7 @@
 
   Called on listening channels (passive openers) when a connection has been
   established with a new remote endpoint that has issued a :meth:`connect`
-  call for the local endpoint.  *conn* is a *new* socket object usable to
+  call for the local endpoint.  *sock* is a *new* socket object usable to
   send and receive data on the connection, and *address* is the address
   bound to the socket on the other end of the connection.

--
assignee: docs@python
components: Documentation
hgrepos: 30
messages: 138594
nosy: docs@python, martin.marcher
priority: normal
severity: normal
status: open
title: Doc Typo
versions: Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12360
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12360] Doc Typo

2011-06-18 Thread Martin Marcher

Martin Marcher mar...@marcher.name added the comment:

Fix repo link :(

--
hgrepos: +31

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12360
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12360] Doc Typo

2011-06-18 Thread Martin Marcher

Changes by Martin Marcher mar...@marcher.name:


--
keywords: +patch
Added file: http://bugs.python.org/file22405/2d9bc44963f6.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12360
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4111] Add Systemtap/DTrace probes

2011-06-18 Thread Martin Marcher

Changes by Martin Marcher mar...@marcher.name:


--
nosy: +serverhorror

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4111
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5672] Implement a way to change the python process name

2010-06-24 Thread Martin Marcher

Martin Marcher mar...@marcher.name added the comment:

Hi,

just scanned the messages. As I read it wontfix actually means:

Ats some point in the future when the setproctitle project 
(http://code.google.com/p/py-setproctitle/source/list) has matured it will be 
reconsidered, correct?

Yes sorry for reopening this after quite some time (~6 months), just happened 
to pop up in my inbox due to the latest nosy list changes...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5672
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5672] Implement a way to change the python process name

2009-10-09 Thread Martin Marcher

Changes by Martin Marcher mar...@marcher.name:


--
nosy: +martin.marcher

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5672
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4094] Future statements Doc from 2.6 refers to 2.5

2008-10-09 Thread Martin Marcher

New submission from Martin Marcher [EMAIL PROTECTED]:

http://docs.python.org/reference/simple_stmts.html#future-statements

says this:


The features recognized by Python 2.5 are absolute_import, division,
generators, nested_scopes and with_statement. generators and
nested_scopes are redundant in Python version 2.3 and above because they
are always enabled.


shouldn't it mention the features recognized by Python 2.6?

--
assignee: georg.brandl
components: Documentation
messages: 74601
nosy: georg.brandl, martin.marcher
severity: normal
status: open
title: Future statements Doc from 2.6 refers to 2.5
versions: Python 2.6

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4094
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Are dictionaries the same as hashtables?

2008-08-26 Thread Martin Marcher
On 2008-08-26 00:32:20, cnb wrote:
 Are dictionaries the same as hashtables?

Yes, but there is nothing in there that does sane collision handling
like making a list instead of simply overwriting.

PS: your sig was *a bit* longer than you question. please don't do
that...


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python's doc problems: sort

2008-06-02 Thread Martin Marcher
Hi,

On Wed, Apr 30, 2008 at 4:48 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 For example, in last week, that page is fetched 550 times.
 The second most popular page, trails quite a distance. Here's the top

yup that was me, i have access to a couple of machines and wanted to
test some intercommunication, I faked most of the user agent strings
but still was locked out by popular pages. I then figured it would be
much better to fetch a useless page a couple of times.

Sorry for the lognoise...

/martin

-- 
http://www.xing.com/profile/Martin_Marcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: self.var hmm?

2008-05-20 Thread Martin Marcher
Hi,

that's because

self.group is not the same as TaskGroup.group

quickish:

class TaskGroup
  group = []
  def __init__(self):

  ## note that all TaskGroup instances now use the the same self.group

self.group = TaskGroup.group
  def addTask(self, task):
self.group.append(task)

hth
martin

On Tue, May 20, 2008 at 10:58 PM,  [EMAIL PROTECTED] wrote:
 class TaskGroup:
def __init__(self):
self.group = []

def addTask(self, task):
self.group.append(task)


 is this wrong? i have a program thats too big to post but should i
 just do group.append in addTask?

 reason is when later doing TaskGroup.group i get None

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




-- 
http://www.xing.com/profile/Martin_Marcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: preserve history in the interactive python

2008-05-20 Thread Martin Marcher
Hi,

On Tue, May 20, 2008 at 8:19 PM, Nikhil [EMAIL PROTECTED] wrote:
 Nikhil wrote:
 the previous interactive shell. Basically, is there anyway that I can
 preserve the history in the shell?

 I figured it out. This below thing works fine for me.
 BTW, I got it from http://docs.python.org/tut/node15.html. A little search

Didn't even think of that, now that I have it: I love you - it's great.

To the one that implemented this: If you ever come to vienna, drop me
a note I'll get you a $FAVORITE_DRINK_HERE

/martin

-- 
http://www.xing.com/profile/Martin_Marcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if string is an integer?

2008-04-08 Thread Martin Marcher
hmmm

int() does miss some stuff:

 1E+1
10.0
 int(1E+1)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: invalid literal for int() with base 10: '1E+1'

I wonder how you parse this?

I honestly thought until right now int() would understand that and
wanted to show that case as ease of use, I was wrong, so how do you
actually cast this type of input to an integer?

thanks
martin


-- 
http://tumblr.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to check if string is an integer?

2008-04-08 Thread Martin Marcher
arg, as posted earlier:

int(10.0) fails, it will of course work with float(1E+1) sorry for
the noise...

On Tue, Apr 8, 2008 at 10:32 PM, Martin Marcher [EMAIL PROTECTED] wrote:
 hmmm

  int() does miss some stuff:

   1E+1
  10.0
   int(1E+1)
  Traceback (most recent call last):
   File stdin, line 1, in module
  ValueError: invalid literal for int() with base 10: '1E+1'

  I wonder how you parse this?

  I honestly thought until right now int() would understand that and
  wanted to show that case as ease of use, I was wrong, so how do you
  actually cast this type of input to an integer?

  thanks
  martin


  --
  http://tumblr.marcher.name
  https://twitter.com/MartinMarcher
  http://www.xing.com/profile/Martin_Marcher
  http://www.linkedin.com/in/martinmarcher

  You are not free to read this message,
  by doing so, you have violated my licence
  and are required to urinate publicly. Thank you.




-- 
http://tumblr.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


plpythonu+postgrs anybody using it?

2008-04-02 Thread Martin Marcher
Hello,

I just started on working with a postgres project, the DB looks really
bad and isn't normalized in any way... 4k Text messages representing a
whole protocol which need to be transformed. Somehow it just doesn't
seem right to put this stuff directly in the database and creating a
bunch of stored procedures (SP) to parse them but I'm not the one to
decide it...

My main concern is that when things start getting more complicated
that everytime a SP is called an instance of the interpreter ist
started which would be a huge slowdown, so does plpythonu run
continiously a python process or does it start one everytime a SP is
called?

-- 
http://tumblr.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking if a variable is a dictionary

2008-03-06 Thread Martin Marcher
On Thu, Mar 6, 2008 at 2:06 PM, Guillermo
[EMAIL PROTECTED] wrote:
  What makes you say you need to know this ? Except for a couple corner
  cases, you usually don't need to care about this. If you told us more
  about the actual problem (instead of asking about what you think is the
  solution), we might be of more help...

  I want to iterate recursively a dictionary whose elements might be
  strings or nested tuples or dictionaries and then convert values to a
  tagged format according to some rules.

just do so, if it's not a dict you can always catch the exception,
then handle tuples (or the exception), then strings which should work
always (of course also error handling here according to your needs)

  I'm just designing the algorithm, but I think Python dictionaries can
  hold any kind of sequence?

python dicts can hold any kind of object (as a value). What you can't
do is have a list as the key, but that is easily circumvented by using
a tuple (or any other immutable type).


hth
martin

-- 
http://tumblr.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encrypting a short string?

2008-02-11 Thread Martin Marcher
Hi,

On 2/11/08, erikcw [EMAIL PROTECTED] wrote:
 In essence what I'm doing is trying to manage tickets for a helpdesk.
 I want the ticket identifier to be short enough to fit in the subject
 line along with the normal subject chosen by the user.  So
 cryptographic security isn't really important.  I can't use the from:
 field because a single user could have multiple tickets.

I've always wondered why such systems don't use the Message-ID or
Reference headers - I know they aren't preserved by all mailers but I
think that having this info in the subject line is

a) visually disturbing (subjective)
b) I guess that the risk of a user modifying the subject line is the
same than finding a programm that doesn't to some extent honor the
headers i mentioned...
flame
c) Personally whenever I find a mail that says please keep this in the
subject I delete that number on purpose...
/flame

martin
-- 
http://noneisyours.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email module, how to add header to the top of an email?

2008-01-24 Thread Martin Marcher
On Thursday 24 January 2008 20:32 David Erickson wrote:

 I have been using the Email module and Message class for awhile,
 however I have been unable to find a way to add a header to the top of
 the email similar to what is done with Received: headers... the
 add_header method only appends to the bottom.  Is there someway this
 can be done?


if by bottom you mean added as the new last header than you don't have to
care, afaik email headers do not have a notion of order

e.g

To: [EMAIL PROTECTED]
From: [EMAIL PROTECTED]

is equal to

From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]


if by bottom you mean it's appended to the body...well that is a problem :)

hth
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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

Re: Sorting Large File (Code/Performance)

2008-01-24 Thread Martin Marcher
On Thursday 24 January 2008 20:56 John Nagle wrote:

 [EMAIL PROTECTED] wrote:
 Hello all,
 
 I have an Unicode text file with 1.6 billon lines (~2GB) that I'd like
 to sort based on first two characters.
 
 Given those numbers, the average number of characters per line is
 less than 2.  Please check.

which would be true if 1.599.999.999 had 2 chars and the rest of the lines
just one :)

(but yes that would be an interesting question how to sort a 1 character
line based on the first 2 of that line)

martin





-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: UDP Client/Server

2008-01-23 Thread Martin Marcher
Guilherme Polo wrote:
  class FooRequestHandler(BaseRequestHandler):
 ... def handle(self):
 ... data, addr_info = self.request[1].recvfrom(65534)
 
 Your FooReceiveServer subclasses UDPServer, it already handled the
 recvfrom for you, so, this is wrong.
 

hmm then why do I receive every second request, shouldn't then no data at
all come up?

Also the next thing that would be a problem would be if I do

data = self.request[0]

I do get the data but where would I get the info from to which endpoint I
need to send the answer?

martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


UDP Client/Server

2008-01-22 Thread Martin Marcher
Hello,

I created a really simple udp server and protocol but I only get every 2nd
request (and thus answer just every second request).

Maybe someone could shed some light, I'm lost in the dark(tm), sorry if this
is a bit oververbose but to me everything that happens here is black magic,
and I have no clue where the packages go. I can't think of a simpler
protocol than to just receive a fixed max UDP packet size and answer
immediately (read an echo server).

thanks
martin


### server
 from socket import *
 import SocketServer
 from SocketServer import BaseRequestHandler, UDPServer
 class FooReceiveServer(SocketServer.UDPServer):
... def __init__(self):
... SocketServer.UDPServer.__init__(self, (localhost, 4321),
FooRequestHandler)
...
 class FooRequestHandler(BaseRequestHandler):
... def handle(self):
... data, addr_info = self.request[1].recvfrom(65534)
... print data
... print addr_info
... self.request[1].sendto(response, addr_info)
...
 f = FooReceiveServer()
 f.serve_forever()
request 0
('127.0.0.1', 32884)
request 1
('127.0.0.1', 32884)
request 2
('127.0.0.1', 32884)
request 2
('127.0.0.1', 32884)
request 2
('127.0.0.1', 32884)



### client
 target = ('127.0.0.1', 4321)
 from socket import *
 s = socket(AF_INET, SOCK_DGRAM)
 for i in range(10):
... s.sendto(request  + str(i), target)
... s.recv(65534)
...
9
Traceback (most recent call last):
  File stdin, line 3, in module
KeyboardInterrupt
 s.sendto(request  + str(i), target)
9
 str(i)
'0'
 for i in range(10):
... s.sendto(request  + str(i), target)
... s.recv(65534)
...
9
'response'
9
'response'
9
Traceback (most recent call last):
  File stdin, line 3, in module
KeyboardInterrupt
 #this was hanging, why?
...
 s.sendto(request  + str(i), target)
9
 s.recv(65534)
'response'
 s.sendto(request  + str(i), target)
9
 s.recv(65534)
Traceback (most recent call last):
  File stdin, line 1, in module
KeyboardInterrupt
 s.sendto(request  + str(i), target)
9
 s.sendto(request  + str(i), target)
9
 s.recv(65534)
'response'
 s.recv(65534)
Traceback (most recent call last):
  File stdin, line 1, in module
KeyboardInterrupt
 s.sendto(request  + str(i), target)
9


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


[OT] Valid Mail addresses modifications (WAS: Re: Looping through the gmail dot trick)

2008-01-21 Thread Martin Marcher
Martin Vilcans wrote:

 Try the SMTP spec. IIRC there's a passage there that says that the
 server should try to make sense of addresses that don't map directly
 to a user name. Specifically, it says that firstname.lastname should
 be mapped to the user with those first and last names.

Short story long:

there aren't any!

FYI:

https://mail.google.com/support/bin/answer.py?answer=10313topic=1564

that was the only reference i found, http://www.ietf.org/rfc/rfc0821.txt
doesn't mention anything beside EXPN which still treats the localpart
literally and checks for a mailbox (or alias) as literally found in the
localpart.

Personally I think google's doing wrong here. Just don't do it anywhere
else, as it's unlikely your mail will reach the person you intended to send
it.

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Looping through the gmail dot trick

2008-01-21 Thread Martin Marcher
Steven D'Aprano wrote:
 Postfix, I think, interpets foo+bar the same as foo.

yup it does, but foo has to be a valid localpart so

foo+bar - foo
foo+baz - foo
f+oobar - f - which is a different user (aliases set aside)

famous call on plus addressing, and you it's just a default you can specify
anything you want but it has to be _after_ the full localpart without
address extensions.

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Looping through the gmail dot trick

2008-01-20 Thread Martin Marcher
On Sunday 20 January 2008 17:38 Joshua Gilman wrote:

 So I have a very interesting task ahead of me and it is to loop through an
 email using the 'gmail dot trick'. Essentially this trick puts periods
 throughout your email to make it look different. Even though it has
 periods gmail will replace them all and send it to that email.

are you saying that when i have 2 gmail addresses

[EMAIL PROTECTED] and
[EMAIL PROTECTED]

they are actually treated the same? That is plain wrong and would break a
lot of mail addresses as I have 2 that follow just this pattern and they
are delivered correctly!

Do you have any reference on that where one could read up why gmail would
have such a behaviour?

 So [EMAIL PROTECTED] is the same as [EMAIL PROTECTED]

To my best knowledge it is not the same and must not be the same. The
localpart of an email is entirely up to the receiving mailserver and cannot
be tempered with without risking misdelivery (at least). If I'm wrong I'd
be gladly corrected, just point me to the references.

/martin


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: sqlite3 is it in the python default distro?

2008-01-13 Thread Martin Marcher
On Saturday 12 January 2008 21:34 Martin Marcher wrote:
 a) Is sqlite included in the python default distribution
 b) In real life can I consider (on linux) that an installation of python
 includes the sqlite stuff?

forgive my that was pebcack. I wasn't reading the docs fully so I thought I
need the python-sqlite or python-sqlite2 (which is in the 2.5 package
on debian/ubuntu at least)


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


sqlite3 is it in the python default distro?

2008-01-12 Thread Martin Marcher
Hello,

I can see that sqlite is in the standard lib documentation:
http://docs.python.org/lib/module-sqlite3.html

however debian and ubuntu (and gentoo according to the packages info) seem
_not_ to include it. 

Now 2 question arise:

a) Is sqlite included in the python default distribution
b) In real life can I consider (on linux) that an installation of python
includes the sqlite stuff?

thanks
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: docstrings style question

2008-01-10 Thread Martin Marcher
Russ P. wrote:

 On Jan 9, 9:47 pm, Steve Brown [EMAIL PROTECTED] wrote:
 I've got a series of modules which look like this:

 #
 #
 # Temperature Sense Test
 #
 #
 class Test3(ar_test.AR_TEST):
 Temperature Sense Test

 I don't like the duplicated information: But the comment is attractive,
 and the docstring self.__doc__ is already in use in the test log. I've
 read that all modules and classes should have docstrings, but I don't
 really have anything else to say, and each module contains only one
 class. I don't think that

 Temperature Sense Test
 class Test3(ar_test.AR_TEST):
 Temperature Sense Test

 would be a real improvement.

 What do you think?

It's still duplicated information.

 I tend to be a bit skimpy with one-line comments for classes and
 methods, but I think a more complete ( style) comment is often
 appropriate for the top of the file.
 
 I'm sure you can think of more to say than Temperature Sense Test.

exactly my opinion

 What temperature? What kind of temperature sensor? What kind of test
 is it, and why are you doing it? That may all be obvious in context,
 but you've provided no context in your post. Also, if the module is of
 any significant size, you might want to provide a clue about who wrote
 it. Then, if someone has a question about it later, they will know who
 to ask.

I tend to mention the main use cases for test classes (especially) and also
a human readable description of what can happen (forgive me the missing
line breaks). Something like this:

class Test3(ar_test.AR_TEST):
Temperature Sense Test.
This class assures that the connection to the hardware sensor can be
established. It also checks a reference sensor that always reports a
certain value so that one can be sure correct data values are reported.


hth
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: help with a problem from school??

2008-01-10 Thread Martin Marcher
Josh wrote:

 Hello all I did a Google search and found this site and was hoping someone
 could help me with what I am sure is a simple question that I cannot
 figure out. Here goes:
  
 Given a simple straight through switch (SPST) with a supply of
 14V, and the need to simulate its intended load of 14mA, what
 would you use to simulate this load?  Please show your
 calculations used to support your answer.

This is a mailing list about the python programming language
(http://www.python.org). I'm not quite sure how your question is related to
python. You might want to try a mailinglist specific to your problem...

martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Collecting Rich Data Structures for students

2008-01-09 Thread Martin Marcher
Paddy wrote:

 On Jan 9, 2:19 am, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:
 Some have offered XML repositories, which I can well
 understand, but in this case we're looking specifically for
 legal Python modules (py files), although they don't have
 to be Latin-1 (e.g. the sushi types file might not have a
 lot of romanji).

Are you asking for

class SushiList(object):
types = [sushi1, sushi2, sushi3, ...]

I don't quite get that, any reference to the original discussion?

/martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: printing dots in simple program while waiting

2008-01-09 Thread Martin Marcher
John wrote:

 import time
 s = '.'
 print 'working', # Note the , at the end of the line
 while True:
 print s
 time.sleep(1)

see my comment in the code above...

if that's what you mean

/martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Look for a string on a file and get its line number

2008-01-08 Thread Martin Marcher
Jeroen Ruigrok van der Werven wrote:

 -On [20080108 09:21], Horacius ReX ([EMAIL PROTECTED]) wrote:
I have to search for a string on a big file. Once this string is
found, I would need to get the number of the line in which the string
is located on the file. Do you know how if this is possible to do in
python ?
 
 (Assuming ASCII, otherwise check out codecs.open().)
 
 big_file = open('bigfile.txt', 'r')
 
 line_nr = 0
 for line in big_file:
 line_nr += 1
 has_match = line.find('my-string')
 if has_match  0:
 print 'Found in line %d' % (line_nr)
 
 Something to this effect.

apart from that look at the linecache module. If it's a big file it could
help you with subsequent access to the line in question

hth
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: use fileinput to read a specific line

2008-01-08 Thread Martin Marcher
jo3c wrote:

 i need to read line 4 from a header file

http://docs.python.org/lib/module-linecache.html

~/2delete $ cat data.txt
L1
L2
L3
L4

~/2delete $ python
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type help, copyright, credits or license for more information.
 import linecache
 linecache.getline(data.txt, 2)
'L2\n'
 linecache.getline(data.txt, 5)
''
 linecache.getline(data.txt, 1)
'L1\n'



-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Open a List of Files

2008-01-08 Thread Martin Marcher
BJ Swope wrote:

 On Jan 8, 2008 6:03 AM, Fredrik Lundh [EMAIL PROTECTED] wrote:
 
 BJ Swope wrote:

  given a list such as
 
  ['messages', 'recipients', 'viruses']
 
  how would I iterate over the list and use the values as variables and
  open the variable names a files?
 
  I tried
 
  for outfile in ['messages', 'recipients', 'viruses']:
  filename = os.path.join(Host_Path, outfile)
  outfile = open(filename, 'w')

files = dict()
l = ['messages', 'recipients', 'viruses']
for f in l:
files[f] = open(s.path.join(Host_Path, outfile), w)

files[messages].write(a string)

hth
martin

PS: Code is untested

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: use fileinput to read a specific line

2008-01-08 Thread Martin Marcher
Fredrik Lundh wrote:

 Martin Marcher wrote:
 
 i need to read line 4 from a header file
 
 http://docs.python.org/lib/module-linecache.html
 
 I guess you missed the using linecache will crash my computer due to
 memory loading, because i am working on 2000 files each is 8mb part.

oops sorry indeed

still the enumerate version seems fine:
 for no, line in enumerate(file(data.txt, r)):
... print no, line
...

someone posted this already i think (or was it another thread?)

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Python's great, in a word

2008-01-07 Thread Martin Marcher
[EMAIL PROTECTED] wrote:
 The best thing about Python is ___.

it's pythonicness.

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Python's great, in a word

2008-01-07 Thread Martin Marcher
On Monday 07 January 2008 21:25 Dustan wrote:

 On Jan 7, 11:40 am, Martin Marcher [EMAIL PROTECTED] wrote:
 it's pythonicness.
 
 it is pythonicness???

not all here are native english speakers, but thanks for the correction.
I'll try to keep it in mind.

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Delete lines containing a specific word

2008-01-06 Thread Martin Marcher
On Sunday 06 January 2008 18:21 Francesco Pietra wrote:

 Please, how to adapt the following script (to delete blank lines) to
 delete lines containing a specific word, or words?
 
 f=open(output.pdb, r)
 for line in f:
 line=line.rstrip()
 if line:
 print line
 f.close()

 import re
 s = [hello, world, , \t ,  , #asdfasdf]
 pattern = re.compile(^\s*$)
 #only hello should be printed as world is a word we want to skip
 for line in s:
... if world in line:
... continue
... if pattern.match(line):
... continue
... if line.startswith(#):
... continue
... print line
...
hello


you have to adapt it to be able to match more than a single word

 If python in Linux accepts lines beginning with # as comment lines, please
 also a script to comment lines containing a specific word, or words, and
 back, to remove #.

yes lines starting with a # are comments in python but that shouldn't be
of concern for your input data. I don't quite get what you want here...

hth
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

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


Re: Delete lines containing a specific word

2008-01-06 Thread Martin Marcher
On Sunday 06 January 2008 21:25 Francesco Pietra wrote:
 yes lines starting with a # are comments in python but that shouldn't
 be of concern for your input data. I don't quite get what you want
 here...
 
 Leaving the lines commented out would permit to resume them or at least
 remeber what was suppressed. During trial and error set up of a
 calculation one never knows exactly the outcome

Ah I get it.

To clarify:
The character python uses as a comment has nothing to do with the character
your data file uses as a comment.

So you could of course use the # sign (which makes sense)
You could also use // (C-Style) or whatever you like

class CommentHelper(object):
Provides the necessary
methods to comment or uncomment a line of text.

# Yes I know this docstring is badly formatted but
# I thought it's nicer to keep the indentation.
def __init__(self, commentStr=None):
if commentStr:
self.commentStr = commentStr
else:
self.commentStr = MY_SUPER_COMMENT_STRING
def commentLine(line):
Comments a line with the
initialized comment string.

return self.commentStr +   + line
def uncommentLine(line):
Uncomments a line iff it is
preceded by the comment string.

if line.startsWith(self.commentStr):
return line[len(self.commentStr)].lstrip()
raise Exception(Can't uncomment Line with no comment)


You want to read up about:
* (new style) classes
* parameters with default values
* docstrings
* Exceptions


That code is untested and may contain errors. I'll let the debugging be your
task :)

hope it points you to the right topics to read up about:
http://docs.python.org/
http://docs.python.org/tut/tut.html
http://www.diveintopython.org/

martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

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


[OT] How is AI implemented

2008-01-03 Thread Martin Marcher
Hi,

I know it's not a trivial field but I had some readings about
artificial intelligence lately and my personal conclusion is that it's
mostly just statistics.

Naively explained:

continiously gather and store information and apply a default rating

1) answer questions with gathered information according to rating
2) store/calculate rating based upon input (be it an interface or user input)
3) goto 1 (sorry for the goto)

So I think that in general there hasn't yet been any artificial
intelligence programmed (Note: I believe I'm aware of the difference
between artificial intelligence and artificial conscusiness where the
second would be able to answer things like: How are you today and
the first can answer factual knowledge)

Am I thinking right here or is there some (preferrably) web reading
available on that or in depth links about the topic?

thanks and sorry for OT posting
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which configparse?

2007-12-06 Thread Martin Marcher
Hi,

On 12/6/07, Neal Becker [EMAIL PROTECTED] wrote:
 configparse looks like what I want, but it seems last commit was 2years
 ago.

 What is the best choice?

that seems like configparse is the best choice. I use it quite often
and no commit in 2years to me means Boy that's stable software. A
search on bugs.python.org mentions 1 enhancement to use for line in
f: instead of while 1:

Why do we always need a ton of commits? For me that means that
developement is still in progress and changes have to be expected
because it's not yet stable.

(Actually not that hard rules, but I hope you get what I meant)

martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to know if folder contents have changed

2007-11-17 Thread Martin Marcher
I think that without further information from the OP about the
requirements all we can do is guessing. So both of our solutions are
just theory after all (just my personal opinion)

2007/11/14, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 On Nov 12, 11:27 am, Martin Marcher [EMAIL PROTECTED] wrote:
  2007/11/12, [EMAIL PROTECTED] [EMAIL PROTECTED]:

  a) create a thread that pulls all the time for changes or

 Given that it would only involve a check of one timestamp (the
 directory the files are located in), I don't think polling from time
 to time would be unreasonable.  The modification timestamp of the
 directory should be sufficient given the use case.  Even if it's not,
 tracking modification times for the files in the directory would not
 be unreasonable.

Not for the 400 Files but the OP asks about more files too. How about
40.000 files or 400.000 files? That could be a problem...

  b) test everytime for changes

 Checking a timestamp should be a very quick operation.  Unless
 everytime occurs *very* frequently, it's certainly not unreasonable.

See above I think it also depends on the number of files

  fam informs in a notification like way.

 FAM would work too.  However,
 1) According to http://oss.sgi.com/projects/fam/faq.html#what_os_fam,
 FAM should be fairly easy to port to ... Unix-like operating
 systems .  If the original poster is a user of a Uniix-like
 operating system he/she may actually be able to use it.  Regardless,
 it seems to me that you would lose a great deal of portability (i.e.,
 is there a Windows port?), which may or may not be important to the
 poster.

I don't use windows so speaking about portability you are right. It
may be a personal thing but I stopped providing solution (or trying to
think about them) for windows (another discussion probably best placed
in a forum about social interests or something)

 2) FAM undoubtedly uses some system resources.  Probably very little,
 but it's still an overhead that must be taken into account.

Both is true but most Linux distributions do use FAM at some point
anyway so the overhead is actually very little. Also I think that on
most OSs there is a similiar thing like FAM that could be used...

 3) You still need to use another method for maintaining state across
 program invocations, do you not?

You need some method no matter wether your program is a long running
process or just invoked in irregular intervals.

After all I'm pretty sure that there is something FAM like that is
available on most OSs. FAM isn't probably available on OSX either but
I guess they provide some mechanism. If you want it really portable
I'd use an abstraction layer that tries to communicate with some
notification daemon which is probably available on the host os and if
all that fails provide a fallback implementation that does naive
tests. All accessible thru the same abstraction interface.

 Using timestamps are:
 1) Portable.  Can you name one OS that does not provide timestamps?
 Last I checked, even Windows does :-)
 2) Storage efficient.  I don't have to actually *store* the
 timestamps.  I can just check to see if a file/directory was modified
 after the last time I checked.

read below, a changed timestamp isn't necessarily a sign that a file
has indeed changed (backups, )

 3) Easy to maintain persistent state -- just store the timestamp!

Well I don't have to actually *store* the timestamps. and
just store the timestamp! are a bit confusing. I think you
absolutely need to store the timestamp since between runs you won't
know what to check for anyway (new files, deleted files, changed files
- if these cases are important to you)

  Personally I'd create a hidden cache file parsable by configparser
  and have filename = $favorite_checksum_algo - key value pairs in it if
  it's not a long running process.

 What is your reasoning for this?

because all I need to do to check for changes is getCache(configFile)
and compare the results to getActual(os.listdir) and those 2 methods
would give me the needed info (of course I'm just blindly guessing as
I don't know anything about the further requirements)

Of course with a lot of files this could be a problem. I wouldn't want
a configparser object with 40.000 (or even just a few thousand)
entries to be alive all the time. You'd probably have to create some
iterator for the file so that you can check thru the entries in a
memory efficient way...

  It seems to me that it is
 inefficient and unreliable.  First of all you have to compute the
 checksum (which undoubtedly would involve reading every byte the file)
 -- not just once, but everytime (or however often you perform the
 check). Secondly, it is possible for the checksum to be the same even
 if the file has changed.  Unlikely?  Perhaps (depends on checksum
 algorithm used).  Impossible?  No.  So, in effect, you are using a
 slow algorithm that is known to give incorrect results in certain
 cases -- all to replace something as basic

Re: how to know if folder contents have changed

2007-11-17 Thread Martin Marcher
I just found this for win32 which seems to be the same as FAM provides:
http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html


So it's not about FAM as a definitive product to be used but more like
something nearer to the OS that is there anyway and will tell you
about it...

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


[OT] The Jew Spam on this list

2007-11-13 Thread Martin Marcher
Hello,

please do not respond to the political spam on this list anymore.
Rather report it as spam to your provider/anti-spam-measures or report
it to the listmasters (if you have the feeling that it helps, I guess
they're already on this issue).

I understand that this might be a heated topic but people please it's
just spam and every message regarding this topic is spam too (funny
enough, so is this message) please just add this stuff to your
killfile or whatever you use.

thanks
martin

PS: if you must discuss this opinion with me answer to me off list as
I guess most people just aren't interested...

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


reading file objects in chunks

2007-11-12 Thread Martin Marcher
Hi,

I'm looking for something that will give me an iterator to a
file-(like)-object. I have large files with only a single line in it
that have fixed length fields like, record length is 26bytes, dataA is
10 bytes, dataB is 16 bytes.

Now when I made my parsing stuff but can't find anything that will let
me read those file efficiently (guess I'm just thinking too
complicated). I'd like to have something like:

f = file(datafile.dat, buffering=26)

for chunk in f.read_in_chunks():
  compute_data(chunk)

f.iter() looked promising at first but somehow it doesn't do the
right thing(tm). also itertools doesn't quite seem to be what I want.
Maybe I just need coffee but right now I'm in the dark.

I'd really like something nicer than

chunksize = 26
f = file(datafile.dat, buffering=chunksize)

chunk = f.read(chunksize)
while len(chunk) == chunksize:
  compute_data(chunk)
  f.read(chunksize)

I just don't feel comfortable with it for some reason I can't explain...

thanks
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to know if folder contents have changed

2007-11-12 Thread Martin Marcher
2007/11/12, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 Why not use the file creation/modification timestamps?

because you'd have to

a) create a thread that pulls all the time for changes or
b) test everytime for changes

fam informs in a notification like way.

Personally I'd create a hidden cache file parsable by configparser
and have filename = $favorite_checksum_algo - key value pairs in it if
it's not a long running process.

Otherwise I'd probably go with fam (or hal i think that's the other
thing that does that)

hth
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression syntax the same in Python, Perl and grep?

2007-11-07 Thread Martin Marcher
2007/11/7, Chris Mellon [EMAIL PROTECTED]:
 On Nov 7, 2007 12:11 PM, [EMAIL PROTECTED]
 [EMAIL PROTECTED] wrote:
  How similar is Python's re module (regular expressions) compared
  to Perl's and grep's regular expression syntaxes?
 

 Somewhat.

  I really hope regular expression syntax is sufficiently standardized
  that
  we don't have to learn new dialects everytime we move from one
  language or shell command to another.

I forgot where I read that so can't back it up but:

Unices are just a collection of different dialects of regex

I think the same is true for about every implementation of regex you
can find. In theory it _should_ be same.

Then again, so should SQL but I bet that it's actually quite hard to
find a single statement that you can literally execute it on all DB
servers (major ones).


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary viewer

2007-11-05 Thread Martin Marcher
2007/11/5, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 On Nov 5, 3:10 pm, Erika Skoe [EMAIL PROTECTED] wrote:
 

 That's funny, I can't see anything.

Of course, it's an empty dict!

tzz, *shaking head*
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Library package import question

2007-11-05 Thread Martin Marcher
2007/11/5, Frank Aune [EMAIL PROTECTED]:
 To prevent namespace pollution, I want to import and use this library in the
 following way:

 import Foo
 (...)
 t = Foo.module2.Bee()

from x import y as z



that has always worked for me to prevent pollution...

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Martin Marcher
2007/10/31, jelle [EMAIL PROTECTED]:
 the subject pretty much says it all.
 if I check a string for for a substring, and this substring isn't found,
 should't the .find method return 0 rather than -1?
 this breaks the

IMHO 0 would mean the substring starts at index 0 of the iterable.

If that changes it should return None in python instead of a int anyway, no?

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Proxying downloads

2007-10-30 Thread Martin Marcher
Hello,

more a recipe question. I'm working on a proxy that will download a
file for a client. The thing that doesn't yield problems is:

Alice (Client)
Bob (Client)
Sam (Server)

1 Alice asks Sam for foobar.iso
2 Sam can't find foobar.iso in cachedir
3 Sam requests foobar.iso from the uplink
4 Sam now saves each chunk received to cachedir/foobar.iso
5 At the same time Sam forwards each chunk to Alice.

But I can't figure out how I would solve the following:

1 Alice asks Sam for foobar.iso
2 Sam can't find foobar.iso in cachedir
3 Sam requests foobar.iso from uplink
4 Sam saves and forwards to Alice
5 At about 30 % of the download Bob asks Sam for foobar.iso
6 How do I serve Bob now?

Now because the internal link is _a lot_ faster than the uplink Bob
will probably reach the end of (the local) foobar.iso before Sam has
received foobar.iso in total from uplink. So Bob will end up with a
incomplete file...

How do I solve that. The already downloaded data should of course be
served internally.

The solutions I think of are
 * Some kind of subscriber list for the file in question
  * That is serve internally and if the state of foobar.iso is in
progress switch to receiving chunk directly from Sam as it comes down
the link
  * How would I realize this switch from internal serving to pass thru
of chunks?

 * Send an acknowledge (lie to the client that we have this file in
the cache) wait until it's finished and then serve the file from the
internal cache)
  * This could lead to timeouts for very large files, at least I think so

 * Forget about all of it and just pass thru from uplink, with a new
request, as long as files are in progress. This would in the worst
case download the file n times where n is the number of clients.
  * I guess that's the easiest one but also the least desirable solution.

I hope I explained my problem somehow understandable.

any hints are welcome
thanks
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sharing vars with different functions

2007-10-29 Thread Martin Marcher
I hate gmail, always forgetting to set the right recipient...


-- Forwarded message --
From: Martin Marcher [EMAIL PROTECTED]
Date: 29.10.2007 10:11
Subject: Re: sharing vars with different functions
To: [EMAIL PROTECTED] [EMAIL PROTECTED]


2007/10/29, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 Im tryin to call a var thats sitting in a function, example:

 i  guess im not graspng the whole global or local var topic..

does this help?

 class Foo(object):
... somevar = [a, b]
... def __init__(self):
... self.another_var = [c, d]
...
 Foo.somevar
['a', 'b']
 f = Foo()
 f.somevar
['a', 'b']
 f.another_var
['c', 'd']
 Foo.somevar = New Value
 f.somevar
'New Value'
 Foo.another_var
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: type object 'Foo' has no attribute 'another_var'



--
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A class question

2007-10-29 Thread Martin Marcher
2007/10/29, Hrvoje Niksic [EMAIL PROTECTED]:
 Sbe unpx inyhr, urer vf n cbffvoyr vzcyrzragngvba:
 ...

was that on purpose?

martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk and recursive deletion

2007-10-28 Thread Martin Marcher
27 Oct 2007 17:38:10 GMT, Marc 'BlackJack' Rintsch [EMAIL PROTECTED]:
 On Sat, 27 Oct 2007 18:07:44 +0200, Martin Marcher wrote:
  I'm playing around with os.walk and I made up del_tree(path) which I
  think is correct (in terms of the algorithm, but not as python wants
  it :)).

 It's not correct in terms of the algorithm if you take the algorithm of
 `os.walk()` into the equation.

 `os.walk()` is itself diving recursivly into the subdirectories…

True but isn't the problem that I need either backtracking to remember
which directories are empty and thus can be deleted or that I need to
do another recursion (like in my function) which returns as soon as
the new root is deleted or at least empty?

I mean having a directory structure with 3 subdiretories, each of them
has files in it

else:
   for subdir in subdirs:
  subdir = os.path.join(cwd, subdir)
  print We need to recurse into: %s % (subdir, )
  del_tree(subdir)

 …and here you are calling the your function recursively which then calls
 again `os.walk()` on that subdirectory.  That's a little bit too much.

I call it recursively here because I

* either need to backtrack to remember which directories are empty (and leafs)
* or I just recurse my function which yields an OSError because a
directory the original os.walk will visit doesn't exist anymore
because some recursion already deleted it.

(correct me if I'm wrong - but I'd like to stick with os.walk for this
as an exercise)

 Or `shutil.rmtree()`.  :-)

Nice function but not part of my exercise :) - No it isn't homework
just doing it to play around.

thanks
martin

PS: as I'm writing this i just discovered that I missed the
topdown=False argument for os.walk. Playing a bit with it the docs
seem to say that is more what I want than topdown=True

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list

os.walk and recursive deletion

2007-10-27 Thread Martin Marcher
Hello,

I'm playing around with os.walk and I made up del_tree(path) which I
think is correct (in terms of the algorithm, but not as python wants
it :)).

As soon as some directory is deleted the iterator of os.walk chokes.
OK that is somehow clear to me as it can't be valid anymore since it
can't go to the just deleted directory but it is in the iterator.

I generated the test data with (bash, don't know of other shell
expansion features)

# root=test
# mkdir $root
# mkdir -p
# 
$root/{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}/{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}
# touch 
$root/{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}/{0,1,2,3,4,5,6,7,8,9}
# touch 
$root/{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}/{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}/{0,1,2,3,4,5,6,7,8,9}

Here goes the script, as far as I tested it it runs fine in test mode.
Now that is just use the print statements like attached below. as soon
as os.rmdir and os.unlink are involved the iterator chokes. How do I
get around that, or what should I use to be able to recursively delete
everything under a certain subdir?

#--snip
import sys
import os
import unittest

def del_tree(path):
   walker = os.walk(path)
   for entry in walker:
  cwd = entry[0]
  subdirs = entry[1]
  files = entry[2]
  print Checking directory: %s %(cwd, )
  if files:
 for file in files:
file = os.path.join(cwd, file)
print The file is now: %s % (file, )
#os.unlink(file)
 print OK directory %s has no more files, checking for
subdirs... % (cwd, )
  else:
 print OK directory %s NEVER HAD FILES, checking for
subdirs... % (cwd, )
  if not subdirs:
 print We can delete: %s % (cwd, )
 #os.rmdir(cwd)
  else:
 for subdir in subdirs:
subdir = os.path.join(cwd, subdir)
print We need to recurse into: %s % (subdir, )
del_tree(subdir)
   #os.rmdir(path)
   print Removing: %s % (path, )
#--snap
-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Eclipse Plugins

2007-10-26 Thread Martin Marcher
2007/10/26, Robert Rawlins - Think Blue [EMAIL PROTECTED]:
 I'm not sure what you IDE you all generally use for your python development.
 I've been somewhat lazy and always used a plain text editor, however this
 technique is starting to take its toll, and it's purely been out of laziness
 not finding myself a decent IDE to develop in. So this morning task is to
 pull my thumb out of my arse and set something up properly.

With Eclipse 3.3 IIRC there is a Dynamic Language IDE Package
available. Out of the box, as far as a I know it only supports ruby. I
didn't look to much into it (out of the same reasons you named). Maybe
that could do something with a few tweaks or additional plugins.

 For my other languages, such as HTML, ColdFusion, JAVA etc I make good use
 of the Eclipse SDK, and I'm looking for some advice on the best and most
 popular python plug-ins available, what would you suggest? I downloaded one
 called PyDev which looked ok but nothing too exciting.

I just switched to using emacs. Still struggling with it but it has
some nice features

C-c C-h - to find the help of something
C-c C-c - to run the buffer (file) I'm currently editing

a few commands which are customizeable enough to run highlighted text
(where IIRC one can define stuff to pre setup an environment if for
example you need to run a method of a class)

and some other nifty stuff. Be aware the learning curve is quite high

(for the vim guys. I've been using vim before but for my use case
emacs provides just more stuff that just works. vim may also be your
choice with a few tweaks it does a lot, and it does it fast)

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Standard Full Text Search Engine

2007-10-26 Thread Martin Marcher
Hello,

is there something like a standard full text search engine?

I'm thinking of the equivalent for python like lucene is for java or
ferret for rails. Preferrably something that isn't exactly a clone of
one of those but more that is python friendly in terms of the API it
provides.

Things I'd like to have:

 * different languages are supported (it seems most FTSs do only english)
 * I'd like to be able to provide an identifier (if I index files in
the filesystem that would be the filename, or an ID if it lives in a
database, or whatever applies)
 * I'd like to pass it just some (user defined) keywords with content,
the actual content (as string, or list of strings or whatever) and to
retrieve the results by search by keyword
 * something like a priority should be assignable to different fields
(like field: title(priority=10, content=My Draft),
keywords(priority=50, list_of_keywords))

Unnecessary:

 * built-in parsing of different files

The standard I'm referring to would be something with a large and
active user base. Like... WSGI is _the_ thing to refer to when doing
webapps it should be something like $FTS-Engine is _the_ engine to
refer to.

any hints?

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Full Text Search Engine

2007-10-26 Thread Martin Marcher
2007/10/26, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 On Oct 26, 8:53 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  Martin Marcher wrote:
 Thanks for the NUCULAR mention (http://nucular.sourceforge.net).  It
 certainly doesn't meet all the requirements requested (very few users
 yet, some features missing).  Please give it a look, however.  It's easy to 
 use
 and fast.  How fast it is compared to others I can't say, especially
 since some of the numbers I see quoted out there are really incredible (how
 can an indexer by faster than cp?) -- I suspect some sort of
 trickery,
 frankly.

For starters I think I will go with nucular. It seems good enough,
lightweight and easy to use.

 Anyway, if you want a feature like proximity searching or
 some sort of internationalization support (it works with unicode, but
 that's probably not enough), please let me know.  I focused on
 the core indexing and retrieval functionality, and I think a lot of
 additional features can be added easily.

I don't know much about the internals of search engines but I'll
probably report back with a few suggestions after some time of usage
:)


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: print vs sys.stdout.write, and UnicodeError

2007-10-25 Thread Martin Marcher
25 Oct 2007 17:37:01 GMT, Brent Lievers [EMAIL PROTECTED]:
 Greetings,

 I have observed the following (python 2.5.1):

  import sys
  print sys.stdout.encoding
 UTF-8
  print(u'\u00e9')
 é
  sys.stdout.write(u'\u00e9\n')
 Traceback (most recent call last):
   File stdin, line 1, in module
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
 position 0: ordinal not in range(128)

 sys.stdout.write(u'\u00e9\n'.encode(UTF-8))
é

 Is this correct?  My understanding is that print ultimately calls
 sys.stdout.write anyway, so I'm confused as to why the Unicode error
 occurs in the second case.  Can someone explain?

you forgot to encode what you are going to print :)

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list

crontab library

2007-10-24 Thread Martin Marcher
Hello,

is anyone aware of a crontab library.

Possibly even more complete, something that will let me
create/manipulate/delete crontab entries in a nice way and install the
new crontab accordingly.

I had a look at the crontab docs and never realized how complex it
actually is. So before I spend time in creating such a thing maybe
someone did it already :)

thanks
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: crontab library

2007-10-24 Thread Martin Marcher
2007/10/24, Guilherme Polo [EMAIL PROTECTED]:
 2007/10/24, Martin Marcher [EMAIL PROTECTED]:
  I had a look at the crontab docs and never realized how complex it
  actually is. So before I spend time in creating such a thing maybe
  someone did it already :)
 

 When you say complex, are you talking about the possible ways to
 define when your job runs ? You could use a parser for the time format
 it uses, like this:
 http://umit.svn.sourceforge.net/viewvc/umit/branch/ggpolo/umitCore/CronParser.py?revision=1175view=markup

This looks nice for starters. But the crontab(5) manpage has a lot
more - that's what I meant by complex. I guess it's just quite some
typing work :)

 * lists
  * 1,2,4
 * ranges
  * 1-3
 * steps
  * 1-12/2
  * */3
 * specials
  * @annually
  * @weekly
  * @daily
  * ...
 * mixes there of
  * 1-4,6,16-22/3
(this actually depends on which cron you use, the
lowest common denominator would be to use either lists or ranges
(or ranges with steps))

Then there is the difference of roots crontab where whe have a line
like this:

# minute hour dom month dow user command
0 * * * * nobody echo foo

A users crontab
# minute hour dom month dow command
0 * * * * echo foo

and all the variables one could use. with a few of them being
mandatory (LOGNAME, or USER depending on the OS), some of them being
standard variables (SHELL,
PATH) and of course custom variables.


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Test for a unicode string

2007-10-24 Thread Martin Marcher
2007/10/24, goldtech [EMAIL PROTECTED]:
 Question: Is there a way to test a string for unicode chars (ie. test
 if a string will throw the error cited above).

yes there ist :)

 isinstance(ua, basestring)
True
 isinstance(ua, unicode)
True
 isinstance(a, unicode)
False
 isinstance(a, str)
True
 isinstance(ua, str)
False


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Vim and Vim-Python

2007-10-24 Thread Martin Marcher
Hello,

2007/10/24, Daniel Folkes [EMAIL PROTECTED]:
 I am new to using Vim's scripts.
 I was wondering if anyone uses Vim-Python and how to use it?   This
 includes things like key bindings and such.

are you talking about

* how to use vim?
 * http://www.vi-improved.org/tutorial.php
* how to create vim scripts?
 * sorry can't help (but vim.sf.net has a couple of scripts you might
want to look at)
* how to use vim to create python scripts?
 1. http://www.vi-improved.org/tutorial.php
 2. http://docs.python.org/tut/tut.html

Personally I just left vim in favor of emacs - there's just a lot more
available that is ready to use vim emacs than with vim (in my case,
your use case may vary)

hth
martin


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++ version of the C Python API?

2007-10-23 Thread Martin Marcher
2007/10/21, Robert Dailey [EMAIL PROTECTED]:
 On 10/21/07, Martin v. Löwis [EMAIL PROTECTED] wrote:
  No, I literally meant that the Python C API is object-oriented.
  You don't need an object-oriented language to write object-oriented
  code.

 I disagree with this statement. C is not an object oriented language,
 and I've seen attempts to make it somewhat object oriented, however it
 failed miserably in readability and manageability overhead.

just FYI. What about the linux kernel? It's (in large parts) perfectly
designed by OO principles (the vfs for example). And I can't remember
that it was written in C++.

Make a struct with some funtion pointers in it and you are at a basic
OO level. the pointers could then manipulate the variables in the
struct (remember a C++ struct ist just a class with all things being
public).

How does that differ from python? - I can't remember having visibility
modifiers in python (so that would lead to that python isn't
object oriented as any programmer could at any time directly
manipulate any method/variable/whatsoever of your classes)


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: test if email

2007-10-12 Thread Martin Marcher
2007/10/12, Grant Edwards [EMAIL PROTECTED]:
 On 2007-10-12, Florian Lindner [EMAIL PROTECTED] wrote:

  I was just asking for the correct syntax of the mail address. I know about
  the various problems actually impossibility to test for a live and valid
  address.

 Don't forget to allow uucp style bang addresses.  :)

no need to get there most forms won't accept the new top level domains (.name).

No need to speek of plus addressing or older messaging systems.

Heck just check for an @ and try to deliver it. (if there's no @ you
should know wether it's a local user or not)

hth
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: We need PIGs :)

2007-08-30 Thread Martin Marcher
Hello,

On 30 Aug 2007 07:14:25 GMT, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 On Thu, 30 Aug 2007 07:10:47 +0200, Martin Marcher wrote:

  Does that sound like a good idea or would that be over formalization?

 Sounds like over engineering/formalization to me.
 You are aware of the Python Enhancement Proposals (PEPs)?

Yes I am thought I mentioned the wsgi pep in the mail...

 Is something like the `Python Database API Specification v2.0`_ or `API
 for Block Encryption Algorithms v1.0`_ what you are looking for?

http://en.wikipedia.org/wiki/Java_Authentication_and_Authorization_Service
http://en.wikipedia.org/wiki/Content_repository_API_for_Java
http://jcp.org/en/jsr/all

But since python is much more open in these terms these hints should
guide developers thru solutions so that they know they can use other
modules/classes without any effort if such a specificaton exists. In
Java it is more like not implementing any of these things is


 .. _API for Block Encryption Algorithms v1.0:
 http://www.python.org/dev/peps/pep-0272/
 .. _Python Database API Specification v2.0:
 http://www.python.org/dev/peps/pep-0249/

Indeed i wasn't aware of these (I know the wsgi spec) but I was more
thinking about guidelines where you can be quite sure that because of
not being able to provide an implementation that is so general that it
could be incorporated in the standard library.

Think of

* object relational mappers (probably a bad example - but would be still nice)
* service registries
* service repositories
* 

that use the same interface so that you can swap them effordlessly.
I'm thinking big here so that generalization has to be applied to the
problems but also that you can keep to well known interface to
implement so that it will work out for the majority of situations in
these fields.

I do know the WSGI spec but I do think that (otherwise I wouldn't have
had the idea) that PEPs are the wrong place for that. To me PEPs are
(better should be) about the plain stock standard library and how to
work with it (coding guidelines, docstring, iterators, generators -
specification of the language) PIGs (given the name is arguable - I
just like it it removes a bit of the necessary formal taste it has)
should define:

* problem
* solution
* expected behaviour
* interface

(probably even prepare unit tests if the interface is stabilized)

but should by itself not implement anything as for example the DBAPI
does. and given the nature of the field (spezialized for a task but
still applies to a lot of people) an general purpose implementation
wouldn't be useful

hope that explains it well enough. I've been in a couple of projects
where problems where common to all those projects but the
specification made up by individual (project) managers made it
impossible to reuse parts of other apps (and I guess with some
official backup one could point back on proven recipies - that's
probably the term that describes it best)

greetings (always wondered is that a formal or informal closing part
in english letters?)
martin
-- 
http://mail.python.org/mailman/listinfo/python-list


We need PIGs :)

2007-08-29 Thread Martin Marcher
Hello,

having worked quite a bit with python in the last months (some Java
before, and some C++ before that) I was very impressed by an idea the
Java people had.

Explanation: the JSRs define how to implement certain services and or
features in Java so that they can be reused. I haven't found such a
thing for python yet.

Say I have the problem of authentication. Now I can implement
authentication against a text file with a key : value format.

However someone may find it more suitable to implement a
authentication backend for exactly this app that can use postgres.

Who else can use the authentication for my program created by a third
party in his or her own app/package/module? To my knowledge noone as
there's nothing you could at least theoretically keep to.

My idea was to define Python Implementation Guidelines (PIGs) that
specify a problem formalize it enough so that implementations are
interchangeable (in this example create a module that has an
authenticate(username, password) method so that one could easily
take that module for any given app and then authenticate against
postgres, and also against my plaintext file (which was the original -
quite useless - implementation).

Does that sound like a good idea or would that be over formalization?

Personally I think that would be great as I could search the PIGs at
(hopefully) python.org find out the number and search at koders.com or
code.google.com for python code that has PIG: XXX in the metadata
docstring or wherever - maybe even a __pig__ = XXX variable.

any input is welcome (also point me to the place where that can be
found if it already exists)
martin
-- 
http://mail.python.org/mailman/listinfo/python-list