splitting by double newline

2011-02-07 Thread Nikola Skoric
Hello everybody,

I'd like to split a file by double newlines, but portably. Now,
splitting by one or more newlines is relatively easy:

self.tables = re.split([\r\n]+, bulk)

But, how can I split on double newlines? I tried several approaches,
but none worked...

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: splitting by double newline

2011-02-07 Thread Nikola Skoric
Dana Mon, 07 Feb 2011 19:20:38 +0100, 
Peter Otten __pete...@web.de kaze:
 with open(filename, U) as f:

Oh, fabulous. Thanks!

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: splitting by double newline

2011-02-07 Thread Nikola Skoric
Dana Mon, 7 Feb 2011 10:02:05 -0800 (PST), 
Ian ian.g.ke...@gmail.com kaze:
 self.tables = re.split(r'(?:\r\n){2,}|\r{2,}|\n{2,}', bulk)

Thanks!

I tried without ?:, but it didn't work. Can you tell me why is it
important that group is noncapturing?


-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


sending through non-default gateway

2011-02-05 Thread Nikola Skoric
Is there a way to create a TCP connection using a gateway of my
choice?

I have a regular user account on a WinXP machine. It has a DNS server
and default gateway configured, and that DNS server and default
gateway don't see the rest of the Internet, just the local
network. But, I know an IP address of another DNS/gateway pair which
is used to access the Internet, and I can ping them (and send nslookup
queries) from my machine.

So, is there a way to tell python don't use my default gateway, here
is an address of the gateway I want you to use? I've been googling,
but to no avail...

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending through non-default gateway

2011-02-05 Thread Nikola Skoric
Dana Sat, 5 Feb 2011 14:13:11 -0800, 
Dan Stromberg drsali...@gmail.com kaze:
 IIRC, this is an instance of what's called source routing, and was
 largely shut off after network admins realized it was a security
 issue.

 Of course, if you have root/administrator permission, you could
 probably do it.  But if you have that, you could probably just fix the
 routing table.

Yeah, I don't have admin priviledges, it's my office computer which is
supposed to be cut of the Internet.

I did a bit of reading on source routing and I'd like to try it. Just
for fun, in case our router accepts such packets. So, is there a way
to do it in python?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


downcasting problem

2010-10-25 Thread Nikola Skoric
Hi everybody,

I need to downcast an object, and I've read repeatedly that if you
need to downcast, you did something wrong in the design phase. So,
instead of asking how do you downcast in python, let me explain my
situation.

I have a 2-pass parser. 1st pass ends up with a bunch of superclass
object, and 2nd pass is supposed to downcast those to one of
subclasses so I can work with them.

Details:

I have a file full of lines which I parse into Line objects. I also
have two subclasses of Line, namely Individual and Family. Constructor
of both subclasses needs all Line objects in the file to be
constructed, so I cannot construct subclass objects in the first pass.

The Python way of doing this (as I understand it) would be to wrap a
subclass around Line and have the Line object as an attribute of a
subclass. Now, this obviously breaks polymorphism and I now have to
reimplement all of Line's classes in subclasses. Although
reimplementation is simple (def method(self): return
self.line.method()), that way of doing things is just not elegant.

So, is there any more elegant solution to my problem?

Thanks in advance.

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: downcasting problem

2010-10-25 Thread Nikola Skoric
Dana Mon, 25 Oct 2010 09:38:42 -0500, 
Tim Chase python.l...@tim.thechases.com kaze:
 While a dirty hack for which I'd tend to smack anybody who used 
 it...you *can* assign to instance.__class__

Wow! Python never stops to amaze me.

 If it breaks you get to keep all the parts :)

Yes, I can see great potential for shit hitting the fan here.

Thanks for the tip!

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what difference does redirection make?

2010-10-18 Thread Nikola Skoric
Dana Sun, 17 Oct 2010 15:36:13 -0400, 
Benjamin Kaplan benjamin.kap...@case.edu kaze:
 On Sun, Oct 17, 2010 at 3:04 PM, Nikola Skoric n...@fly.srk.fer.hr wrote:
 You're trying to write Unicode to a file. But there's no such thing as
/snip
 .encode(cp1252) or whatever encoding you want to use to the end of
 the mytemplate.render_unicode(...) call on the last line.

Thank you, thank you, thank you! I got it now...

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


what difference does redirection make?

2010-10-17 Thread Nikola Skoric
When I execute
n...@rilmir:~/code/simplepyged/docs/examples$ python latex.py
I get expected output (bunch of latex markup).

But, when I add a redirection, I get:
n...@rilmir:~/code/simplepyged/docs/examples$ python latex.py  foo.tex
  File latex.py, line 87, in module
print  mytemplate.render_unicode(stack=stack, index=latex_index(stack), 
pages=pages)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 
625: ordinal not in range(128)

Now, how does python even know I added a redirection?! And then... why
would it care?

Code of latex.py can be seen here:
http://github.com/dijxtra/simplepyged/blob/5ad8e0f14e93bde74520b502e5af71d78ed55bf0/docs/examples/latex.py

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


subclass constructor problem

2010-10-05 Thread Nikola Skoric
I have a superclass Element and a subclass Family. All Family.__init__() does 
is run Element.__init__() and self.__parse(). For some reason it seems like 
self.__parse() isn't run. Here is the code:
http://github.com/dijxtra/simplepyged/blob/8d5a6d59268f6760352783cce6b97c0b5e75b8be/simplepyged/simplepyged.py

In this version everything works fine. Notice lines 698, 703 and 708. If I 
remove those lines, those 3 methods return None or []. Seems like __init__ 
won't run __parse, but other methods run it without problem.

So, what obvious thing am I missing? :-)

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching my own exception

2010-06-20 Thread Nikola Skoric
Dana Sun, 20 Jun 2010 10:53:08 +0200, 
Peter Otten __pete...@web.de kaze:
 Now in your case village.py is first run as the main script and then 
[...]
 In the account module you indirectly raise village.ExceptionWithLongName and 
 in __main__ you try to catch __main__.ExceptionWithLongName.

Phew. I get it now. You're my hero :-D I had to read it twice, but I
got it. Thanks a bunch!

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching my own exception

2010-06-19 Thread Nikola Skoric
Dana Fri, 18 Jun 2010 20:01:45 +0200, 
Peter Otten __pete...@web.de kaze:
 Solution: move your startup code into a separate file and have it import the 
 village module.

Excellent, thanks! Everything works now, but I still don't quite get what the 
problem is...

 You are importing your main script elswhere. Your code then 
 effectively becomes

 try:
 # in another module
 raise village.SomethingBuiltError 
 except __main__.SomethingBeingBuiltError:
print caught

 i. e. you get two versions of every class that are built from the same code 
 but not (recognized as) identical.

What I don't get is: what do you mean I'm importing my main script
elsewhere by runing python village.py? SomethingBuiltError is
defined in the same script that I'm runing, I didn't import it, did I?
If you could please clear it up for me... or point me to relevant
literature, that's also cool, I couldn't find this thing explained
anywhere.

Anyway, thanks for the solution!

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching my own exception

2010-06-19 Thread Nikola Skoric
Dana 18 Jun 2010 17:45:31 GMT, 
Steven D'Aprano st...@remove-this-cybersource.com.au kaze:
 Other than that, I notice that your module throws away useful debugging 
 information, and replaces it with bland, useless pap of no nutritional 
 value:

 try:
 import account, fetch, resources, const
 except Exception:
 raise Exception('One or more travapi modules not available.')

Oh, yes, thanks for pointing that out, that was a dirty hack for
solving some error I was getting with pydoc. I'll remove that, thanks
for pointing that out.

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


including constants

2009-09-13 Thread Nikola Skoric
Hi there,

I have a simple problem and I know how to solve it :-D, but I suspect that
there is a standard solution which is more elegant.

So, here is my problem: I have django app versioned with svn and I
test my trunk on two different machines (one with mysql, another with
sqlite3). How do I remove database-definition constants from my
settings.py and put them in a separate file which wouldn't be
maintained by svn? (did I really hear somebody call that kind of file
unversioned file or did I make that up?) I suppose I could make a
trivial module with database info, import it and then assign my
constants with data from that module, but that looks so unelegant to
me. What's the standard way of doing this?

Thanks in advance.

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


python web programming for PHP programmers

2008-12-24 Thread Nikola Skoric
I0m a python newbie with PHP background. I've tried to make a web app
from one of my python scripts (which I haven't done before) and I
ended up with:

?php
echo shell_exec(python foobar.py);
?
which works really nice :-D

For some reason I can't find no quick and dirty python web
programming tutorial for PHP programmers on google. :-D I don't need
a general python tutorial, I just need a tutorial on how to make a
hello world server side script with python. Any suggestions?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
--
http://mail.python.org/mailman/listinfo/python-list


Re: win32serviceutil won't start

2007-11-28 Thread Nikola Skoric
Dana Mon, 26 Nov 2007 08:50:23 -0800 (PST), 
[EMAIL PROTECTED] [EMAIL PROTECTED] kaze:
 Sorry I didn't reply sooner. If you're creating a service based on a
 Python file, check out the following links in addition to the book
 Wolfgang mentioned:

 http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html
 http://www.thescripts.com/forum/thread595660.html
 http://essiene.blogspot.com/2005/04/python-windows-services.html

 That should get you started. Hope it helps!

Huh. Thank you guys a lot. I took a glance (albeit a rather long one)
and decided that my users will have to install cygwin if they want to
use my script. Service handling is just a bit to complicated (after
creating UNIX daemon with 2 consecutive forks), and I'm not going to
be paid for this :-D

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


win32serviceutil won't start

2007-11-25 Thread Nikola Skoric
I have a very simple win32serviceutil script:
import win32serviceutil, time

win32serviceutil.StartService(burek, localhost)

time.sleep(10)

exit()

It successfuly imports win32serviceutil, and chokes on StartService:
Traceback (most recent call last):
  File foobar.py, line 3, in ?
win32serviceutil.StartService(burek, localhost)
  File C:\Python24\Lib\site-packages\win32\lib\win32serviceutil.py, line 
399, in StartService
hs = SmartOpenService(hscm, serviceName, win32service.SERVICE_ALL_ACCESS)
  File C:\Python24\Lib\site-packages\win32\lib\win32serviceutil.py, line 
76, in SmartOpenService
return win32service.OpenService(hscm, name, access)
pywintypes.error: (1060, 'OpenService', 'The specified service does not 
exist as an installed service.')

What does that mean?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32serviceutil won't start

2007-11-25 Thread Nikola Skoric
Dana Sun, 25 Nov 2007 13:52:35 -0800 (PST), 
[EMAIL PROTECTED] [EMAIL PROTECTED] kaze:
 Looks like Microsoft thinks you mis-spelled it.

 http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/w2000Msgs/3310.mspx?mfr=true

 I would check and see if that service is installed on your PC. You can
 go to Start -- Run and type services.msc

 Scroll through there and see if your service is listed. You might
 check to see if you can enable/disable it via that console as well.

Seems like I misunderstood Windows services (I'm porting UNIX daemon
to Windows so I'm thinking in UNIX terms). I didn't know I have to
_install_ a service before I _start_ it. How do I install a service?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: formated local time

2007-11-16 Thread Nikola Skoric
Dana Thu, 15 Nov 2007 10:12:11 -0600, 
Adam Pletcher [EMAIL PROTECTED] kaze:
 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On
 Behalf
 Of [EMAIL PROTECTED]
 Sent: Thursday, November 15, 2007 9:56 AM
 To: python-list@python.org
 Subject: Re: formated local time
 If you want the formatted string, you can use strftime:
 
  time.strftime(%Y-%m-%d %H:%M:%S)
 '2007-11-15 07:51:12'

 datetime also has the strftime method:

 import datetime
 datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

Thanks everybody!

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


formated local time

2007-11-15 Thread Nikola Skoric
I have been trying to find appropriate way to do get local time in
-mm-dd hh:mm:ss format, but the best I got is this:
datetime.datetime.fromtimestamp(time.mktime(time.localtime()))
It seems to me I'm missing a much simpler method, am I?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


daemon under windows

2007-11-14 Thread Nikola Skoric
I wrote a simple UNIX daemon (using 2 forks) which does a simple job: it 
executes a function, waits for some time, and then executes it again. Now 
I'd like to port that to Windows. How do I create daemon on Windows (since 
I can't use fork)?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


http client using ssh -D

2007-11-02 Thread Nikola Skoric
Is there a python library which supports using SOCKS proxy which I
create by ssh -D port remote-host? I was trying to use that socket
by SocksiPy, but I get channel 3: open failed: administratively
prohibited: open failed on the server side. And I can use that
channel freely with firefox. Any other library I might use?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


getting text inside the HTML tag

2007-07-14 Thread Nikola Skoric
I'm using sgmllib.SGMLParser to parse HTML. I have successfuly parsed start
tags by implementing start_something method. But, now I have to fetch the
string inside the start tag and end tag too. I have been reading through
SGMLParser documentation, but just can't figure that out... can somebody
help? :-)

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list


cron job times out

2006-11-24 Thread Nikola Skoric
Hello,

I have a few lines of code retrieving a web page and saving some 
variables from it to a log. And everything works nice from command line. 
but, when I make a cron job, I get an error:

Your cron job on fly
cd $HOME/bin/ ; python newartlog.py ; cd

produced the following output:

Traceback (most recent call last):
  File newartlog.py, line 11, in ?
response = urllib2.urlopen(req)
  File /usr/local/lib/python2.4/urllib2.py, line 130, in urlopen
return _opener.open(url, data)
  File /usr/local/lib/python2.4/urllib2.py, line 358, in open
response = self._open(req, data)
  File /usr/local/lib/python2.4/urllib2.py, line 376, in _open
'_open', req)
  File /usr/local/lib/python2.4/urllib2.py, line 337, in _call_chain
result = func(*args)
  File /usr/local/lib/python2.4/urllib2.py, line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File /usr/local/lib/python2.4/urllib2.py, line 996, in do_open
raise URLError(err)
urllib2.URLError: urlopen error (145, 'Connection timed out')

It seems that the connection timed out. But, every time I execute the 
script from the command line, everything goes fine. And every time he 
cron job triggers, it times out. How come?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams 
-- 
http://mail.python.org/mailman/listinfo/python-list


forcing exceptions

2006-03-03 Thread Nikola Skoric
Is there a way to tell the interpreter to display exceptions, even those 
which were captured with except?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: forcing exceptions

2006-03-03 Thread Nikola Skoric
In article [EMAIL PROTECTED], Paul Rubin 
http://[EMAIL PROTECTED] says...
 Nikola Skoric [EMAIL PROTECTED] writes:
  Is there a way to tell the interpreter to display exceptions, even those 
  which were captured with except?
 
 Normally you wouldn't do that unless you were trying to debug the
 interpreter itself.  It uses caught exceptions for all sorts of things
 that you probably don't want displayed.  I think even ordinary loop
 termination may be implemented using exceptions.

Yes, thanks for your quick responses, all three. You're right, I don't 
want to debug python :-) But I figured out that I don't need captured 
exceptions, the thing is that I just didn't belive the problem was that 
obvious. In fact, problem was in the except block, not in it's try 
block. The except block had this inocent statement:

print self.sect[1].encode('utf-8')

Which results in:

Traceback (most recent call last):
  File AIDbot2.py, line 238, in ?
bot.checkNominations()
  File AIDbot2.py, line 201, in checkNominations
if sect.parseSect() == 1:
  File AIDbot2.py, line 96, in parseSect
print self.sect[1].encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 15: 
ordinal
 not in range(128)

Now, who can it complain about 'ascii' when I said loud and clear I want 
it to encode the string to 'utf-8'??? Damn unicode.

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams 
-- 
http://mail.python.org/mailman/listinfo/python-list


making 'utf-8' default codec

2006-02-27 Thread Nikola Skoric
Hi there,

Is there a way of making 'utf-8' default codec for the whole program, so 
I don't have to do .encode('utf-8') every time I print out a string?

-- 
Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams
-- 
http://mail.python.org/mailman/listinfo/python-list