Installing Python at Work

2005-10-17 Thread Nikola
I'm currently learning Python for my own use.
I'm considering installing it on a work laptop, knowing that it is
non-licensed, distributable software.

However, does it access communication ports?  I know the company checks
their ports regularly for activity.

I won't be doing anything very serious; I'm just trying out Python,
learning the basics from 'Learning Python' by O'Reilly.

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


Re: Installing Python at Work

2005-10-17 Thread Nikola
Many thanks. I know it sounds like a silly question, but it's the
company's laptop etc.  

Does Python allow conflicting statements? :)

-- 
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: 

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


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


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


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


Re: Time object?

2007-08-02 Thread Nikola Stjelja
On 8/1/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm well aware of the datetime module, however it is really inconsistent
> and useless to me. In order to do any arithmetic on time objects, I have to
> use the 'timedelta' class, which doesn't even allow me to do all the math I
> want to do.
>
> For example, I want to do "1 / timeobj", where timeobj might represent a
> time in the format of "00:00:00.00". Do I have to code my own class
> for this, or is there some other third party library out there that will
> allow me to do this?
>
> Thanks.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Convert each date you use to a timestamp, make all your calculations using
those timestamps, and then when you need a date back just convert the
desired timestamp to date time format of your choosing.

-- 
Please visit this site and play my RPG!

http://www.1km1kt.net/rpg/Marinci.php
-- 
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


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


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


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: [email protected]
>> 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


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: 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


Re: module pickle

2008-01-08 Thread Nikola Stjelja
On Jan 9, 2008 5:29 AM, Beema shafreen <[EMAIL PROTECTED]> wrote:

> Hi I am beginner in python. and I am not able to understand the Pickle
> concept in python can. some body explain me  about the use of this module,
> few examples. which will help me a lot.
>
> regards
> shafreen
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

You can find a good documentation of the pickle module here:
http://docs.python.org/dev/library/pickle.html with exmaples to show you how
you can use it.
Pickle is used to serialize objects. What does that mean? In short you save
your objects( remeber everything is an object in python, strings, lists,
touples, dictionaries ...) to an external file (eg. object.pcl) for later
usage( eg. you save your users personal data when exiting your software, and
then you load it later when your software is restarted by the user.


-- 
Please visit this site and play my RPG!

http://www.1km1kt.net/rpg/Marinci.php
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pet Store

2008-01-08 Thread Nikola Stjelja
On Jan 8, 2008 7:32 PM, George Maggessy <[EMAIL PROTECTED]> wrote:

> Yeap. It is. I'm looking for something like that app. Smth that I
> could base my future developments on.
>
> On Jan 8, 1:47 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> > On Mon, 07 Jan 2008 22:21:53 -0800, George Maggessy wrote:
> > > I'm an experience Java developer trying to learn Python. I just
> > > finished the Python tutorial on python.org and I'm currently reading
> > > the "Learning Python" book. However, if I could find something like a
> > > simple web app with some best practices, such as those famous "Java
> > > Pet Store" apps, I think that would help me to fill up some gaps in my
> > > learning process. Does anybody know any app like that?
> >
> > Isn't that a web application using Java web frameworks?  So you are
> > looking for a Python web framework with a "Pet Store" tutorial?
> >
> > Ciao,
> > Marc 'BlackJack' Rintsch
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If you are looking for a good , well documented , easy to use but powerfull
web framework you deffinitely need to use Django.

-- 
Please visit this site and play my RPG!

http://www.1km1kt.net/rpg/Marinci.php
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python GUI toolkit

2008-02-04 Thread Nikola Stjelja
On Feb 4, 2008 8:18 AM, David Cook <[EMAIL PROTECTED]> wrote:

> On 2008-02-03, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> wrote:
> > what would be the best python GUI toolkit, it must be cross platform.
> >
> > i have tried gtk, but it interface are real bad and its coding was
> difficult
> > so i dropped it,
> >
> > the only remaining are qt4 and wx, i would like to know if one of these
> or
> > any other toolkit is capable of creating good-looking GUI's, like in
> other
> > apps, for e.g, .net apps.
> >
> > i m a noob, and willing to learn, so difficulty is no problem
>
> The real way to see is by installing each along with their respective
> demos,
> looking over some of the demo code, and perhaps coding some simple apps in
> each.
>
> Qt4 has the most polished and complete API.  When judging looks under the
> X-Window System, make sure to run qtconfig and try some of the other
> themes.
>
> WX seems to have more design warts (the layout system takes some getting
> used to), but is quite capable and flexible and probably has the most
> native
> look and feel under win32.  The license is much more liberal for
> commercial
> use.  Also, it comes with OS/X (both Tiger and Leopard), is easy to
> install under MSWindows).


I wouldn't agree with you on that. I use wx on both  windows and gnome
respectively, and on both platforms wx widgets look and feel native. The
layout system is really simple to use, but powerfull, and if you've done
some web design in the past you are going to wrap your head over it just
after a few examples.

I think the most powerfull feature of the wxwidget toolkit it's a very
consistent API. Each widget is created in a very similar manner, so is very
easy to pick and implement new features of the widget. Which can speed up
the learning process quite a bit.

I would sincerly hope to see in the future a python distribution that
incorporates wxwidgets as its basic gui toolkit instead of tkinter.

>
>
> Dave Cook
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Please visit this site and play my RPG!

http://www.1km1kt.net/rpg/Marinci.php

My Poetry Book:
http://www.lulu.de/browse/book_view.php?fCID=222964&fBuyItem=5

My OS Projects:

http://lab.linux.hr/~nstjelja/drawit/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why not a Python compiler?

2008-02-05 Thread Nikola Stjelja
If  you want to create standalone python applications I'd suggest you to use
PyInstaller which is an excellent application that boundles everything you
need to run your application in a standalone package. It works on windows,
linux and I think mac but i'm not sure.

On Feb 5, 2008 10:25 AM, James Matthews <[EMAIL PROTECTED]> wrote:

> You can also compile parts of Python to speed them up!
>
>
> On Feb 5, 2008 9:37 AM, Kay Schluehr <[EMAIL PROTECTED]> wrote:
>
> > On Feb 5, 9:19 am, Santiago  Romero <[EMAIL PROTECTED]> wrote:
> > >  ( Surely if this question has been asked for a zillion of times... )
> >
> > Sure. You can access comp.lang.python via google.google.com. It has a
> > search function.
> >
> >
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
>
> --
> http://search.goldwatches.com/?Search=Movado+Watches
> http://www.jewelerslounge.com
> http://www.goldwatches.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Please visit this site and play my RPG!

http://www.1km1kt.net/rpg/Marinci.php

My Poetry Book:
http://www.lulu.de/browse/book_view.php?fCID=222964&fBuyItem=5

My OS Projects:

http://lab.linux.hr/~nstjelja/drawit/
-- 
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:


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: wx

2008-09-11 Thread Nikola Stjelja
The module you are talking about is a python GUI toolkit named WxPython,
which is a port of the cross platform C++ GUI toolkit wxwidgets. It's an
excelent gui toolkit , easy to learn and code on. Well documented and has an
excelent community around it. Here are the links for both sites:
http://www.wxpython.org/
http://www.wxwidgets.org/

On Thu, Sep 11, 2008 at 8:16 PM, Desmond Scott E <[EMAIL PROTECTED]> wrote:

>  I'm am a Python novice by chance not choice.  (Although it appears to be
> a nice tool.  Plus anything based on Monte Python can't be bad!)
>
> My Quest is to migrate a Python-based process from Windows2000/Python
> v2.4.2 (#67) to WindowsXP/Python v2.5.2 (r252:60911).
>
> I've searched the Python website and could find no reference to module wx.
> Is this an add-in module or perhaps it was replaced in v2.5.2???
>
> References in the code are:
> wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)
> self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
> self.SetColumnWidth(0, WX.LIST_AUTOSIZE))
> idx = self.GetNextItem(idx, wx.LIST_NEXT_ALL, wx.LIST_STATE_DONTCARE)
>
> Any help would be greatly appreciated!  I do have Shrubbery!
>
> Scott
>
> Scott E. Desmond
> Director & Manager Equity Systems Development
> IT Integration Lead
> Mellon Capital Management Corporation
> 500  Grant Street, Suite 4200
> Pittsburgh, PA  15258
> T 412.236.0405 | F 412.236.1703
> [EMAIL PROTECTED] | *www.mcm.com*
>
> *The information contained in this e-mail may be confidential and is
> intended solely for the use of the named addressee.*
> *Access, copying or re-use of the e-mail or any information contained
> therein by any other person is not authorized.*
> *If you are not the intended recipient please notify us immediately by
> returning the e-mail to the originator.(16b)*
> **
> Disclaimer Version MB.US.1
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
My Blog:
http://mylifeasadeveloper.blogspot.com/

My home page:
http://www.inet.hr/~nstjelja

My Poetry Book:
http://www.lulu.de/browse/book_view.php?fCID=222964&fBuyItem=5

My OS Projects:

http://lab.linux.hr/~nstjelja/drawit/
--
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  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


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 <[email protected]> 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  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


Re: catching my own exception

2010-06-19 Thread Nikola Skoric
Dana Fri, 18 Jun 2010 20:01:45 +0200, 
Peter Otten <[email protected]> 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  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


Re: catching my own exception

2010-06-20 Thread Nikola Skoric
Dana Sun, 20 Jun 2010 10:53:08 +0200, 
Peter Otten <[email protected]> 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


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


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


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 
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


Re: what difference does redirection make?

2010-10-18 Thread Nikola Skoric
Dana Sun, 17 Oct 2010 15:36:13 -0400, 
Benjamin Kaplan  kaze:
> On Sun, Oct 17, 2010 at 3:04 PM, Nikola Skoric  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


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  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