Re: Documenting properties

2005-09-27 Thread Paul McNett
Lasse Vågsæther Karlsen wrote:
> So, my question is, is there a way to get __doc__ support for
> properties, in effect, use the """xxx""" syntax for documenting properties.

Yes, the property() function accepts a doc argument, as in:

property(fget, fset, fdel, doc)

ex:
MyProp = property(_get, _set, None, "This will show up in __doc__")


> Is the preferred way to use """xxx""" or # to document ?

# is for source code commenting (audience is the person reading your
code). """x""" is for documenting your API (audience is the person using
your code). They are quite different.


> Whatever is preferred, what's the upside/downsides of the two beyond
> what I just explained?

Nothing really, but something handy to keep in mind is that the string
literal ("""x""") can be used to block out huge sections of code during
testing, where you'd have to put a # in front of every line otherwise.

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com


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


Re: how to modify text in html form from python

2005-10-21 Thread Paul McNett
Philippe C. Martin wrote:
> PS: If my question is not clear, I am trying to "share" the form between the
> client and server.
> 
> just as many sites out there allow you to modify existing data:
> 1) the server pops up a form with your data in it.
> 2) the client can modify it and submit.
> 
> I know this is a _basic_ question, sorry.

When debugging Python cgi scripts, it is helpful to run the scripts from a
command line just to make sure there aren't any compiler errors. Depending on
how the server is set up, you'll get a server error or just a blank page if your
script won't compile. When I run your script directly as I suggest, here's what
I get:

[EMAIL PROTECTED]:~$ python test.py
   File "test.py", line 23
 
 ^
SyntaxError: invalid syntax

D'oh! You needed to surround the html with quotes to make it a string, as in:

print """

...

"""

I don't really understand your original problem, but perhaps this will help get
you rolling again.


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com


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


Re: exceptions, internals (introspection?)

2005-11-10 Thread Paul McNett
ej wrote:
> I have often wondered how to get at other internals, such as the name of
> the current function, file, line number I am in?  The arguments to the
> current function, etc. 

Others have given you information on how to get at the stack trace. But 
regarding getting at some of the other internals you are talking about:

 >>> import inspect
 >>> help(inspect)

Back to exceptions, you can also provide your own global exception handler by 
overriding sys.excepthook (drop in your own function).

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: wxGrid and Focus Event

2005-11-29 Thread Paul McNett
lux wrote:
> How can I capture the EVT_SET_FOCUS on a wxGrid?

If you want to catch when the grid as a whole gets the focus, use:

 >>> grid.Bind(wx.grid.EVT_SET_FOCUS, self.onGridFocus)


If you want to catch when a cell in the grid gets the focus, use:

 >>> grid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.onCellSelected)


And, your questions will be better on the wxpython-users list at
http://wxpython.org/maillist.php


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: wxGrid and Focus Event

2005-11-29 Thread Paul McNett
Paul McNett wrote:
> lux wrote:
> 
>>How can I capture the EVT_SET_FOCUS on a wxGrid?
> 
> 
> If you want to catch when the grid as a whole gets the focus, use:
> 
>  >>> grid.Bind(wx.grid.EVT_SET_FOCUS, self.onGridFocus)

Oops, my bad:

 >>> grid.Bind(wx.EVT_SET_FOCUS, self.onGridFocus)


> If you want to catch when a cell in the grid gets the focus, use:
> 
>  >>> grid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.onCellSelected)
> 
> 
> And, your questions will be better on the wxpython-users list at
> http://wxpython.org/maillist.php
> 
> 


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: wxGrid and Focus Event

2005-11-29 Thread Paul McNett
lux wrote:
> Can you try this code?

Sure, thanks for posting it!


> If you press only the TAB key
> the focus go from the TextCtrl to the Grid (I suppose)
> but onGridFocus in not called.

Confirmed, at least on Gtk.


> any idea?

Yep, the grid is actually a collection of subwindows, and I made the guess that 
the first window to get the focus is actually that little corner window at the 
intersection of the column labels and the row labels. Try this instead:

>>> g.GetGridCornerLabelWindow().Bind(wx.EVT_SET_FOCUS, onGridFocus)


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: wxGrid and Focus Event

2005-11-29 Thread Paul McNett
lux wrote:
> TANKS!!!
> Now it work!!!

Not so fast. I've found out that I had to do the following ugly workaround to 
ensure it works in all cases:

def _initEvents(self):
...
if self.BaseClass.__name__ == "dGrid":
## Ugly workaround for grids not firing focus events from the 
keyboard
## correctly.
self._lastGridFocusTimestamp = 0.0
self.GetGridCornerLabelWindow().Bind(wx.EVT_SET_FOCUS, 
self.__onWxGotFocus)
self.GetGridColLabelWindow().Bind(wx.EVT_SET_FOCUS, 
self.__onWxGotFocus)
self.GetGridRowLabelWindow().Bind(wx.EVT_SET_FOCUS, 
self.__onWxGotFocus)
self.GetGridWindow().Bind(wx.EVT_SET_FOCUS, self.__onWxGotFocus)
self.Bind(wx.EVT_SET_FOCUS, self.__onWxGotFocus)
...


def __onWxGotFocus(self, evt):
if self.BaseClass.__name__ == "dGrid":
## Continuation of ugly workaround for grid focus event. Only 
raise the
## Dabo event if we are reasonably sure it isn't a repeat.
prev = self._lastGridFocusTimestamp
now = self._lastGridFocusTimestamp = time.time()
if now-prev < .05:
return
self.raiseEvent(dEvents.GotFocus, evt)

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: wxGrid and Focus Event

2005-11-29 Thread Paul McNett
Bugs wrote:
> So Paul, are you saying there's a bug with the wxGrid control and if so, 

Yes, I think it is a bug.


> do you know if there's been a bug-report submitted to the wxWidgets 
> and/or wxPython folks?

I don't know, but I've been meaning to check.


> Or is this just the way the wxGrid control works?
> Thanks!

wxPython/wxWidgets, like any GUI toolkit, is pretty complex. For the most part 
all the commonly-needed things work just fine - it is when you venture into the 
less-used things that you get into trouble.

If I filed a proper bug report for everything wrong with wxPython/wxWidgets, 
I'd 
probably not get anything else done. But on the other hand you couldn't force 
me 
to stop using wxPython if you tried!


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: an intriguing wifi http server mystery...please help

2005-11-29 Thread Paul McNett
[EMAIL PROTECTED] wrote:
> 1)
> Laptop wired, client
> Desktop wired, server
> GREAT!
> webpage served in 2 seconds
> 
> 2)
> Laptop wired, server
> Deskop wired, client
> GREAT!
> webpage served in 2 seconds
> 
> 3)
> Laptop wireless, client
> Desktop wireless, server
> GREAT!
> webpage served in 2 seconds
> 
> 4)
> Laptop wireless, server
> Desktop wireless, client
> CRAP!
> webpage served in 90 seconds
> 
> 
> What the heck is happening?

Please post your routing tables and, if you are referencing your server machine 
by name, your name server addresses (/etc/resolv.conf on Linux).


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: an intriguing wifi http server mystery...please help

2005-11-30 Thread Paul McNett
[EMAIL PROTECTED] wrote:
> Please excuse any ignorance here.
> I would love to show you what you are asking for, but I am not sure
> what you are asking for (newbie here).
> 
> All these connections (i.e. client-server connections) are within my
> local area network.
> 
> I have a simple linksys 802.11b router.
> My server is set to say, "192.168.1.100", port ,
> and my client is set to say, "192.168.1.101"
> 
> I load up the server, then go to the client computer webbrowser and
> enter "http://192.168.1.100:";

If you are on Windows, please open a command window (Start|Run and then type 
'cmd') and type:

route print

On Linux or Mac, the command would simply be:

route


Do this on both computers, and post the output here. If you are using ip 
addresses only in your URL's the problem isn't with DNS or name lookup so let's 
eliminate a routing problem next.

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: wxPython installation issues on Debian

2005-11-30 Thread Paul McNett
[EMAIL PROTECTED] wrote:
> Thanks a lot for the clarification. I don't have a compelling reason
> not to use 2.3 other than having to install the modules I've already
> set up for 2.4. Not really a big deal. Looks like I'll be switching to
> 2.3.

Umm, for what it's worth: I'm on Ubuntu (a Debian derivative), using Python 
2.4.2 and wxPython 2.6. The wxPython was installed using 'apt-get install 
python-wxGtk2.6'.

So I don't know why you say you need to use Python 2.3 as I don't even have 
that 
on my system.

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: wxPython installation issues on Debian

2005-11-30 Thread Paul McNett
Robert Kern wrote:
> Although Ubuntu is a Debian derivative, it does have different packages.
> At the moment, Debian's default Python is 2.3 although one can also
> install Python 2.4, and most Python packages in Debian have been built
> for both (that's why I erroneously recommended installing the apparently
> nonexistant python2.4-wxgtk2.4). However, it appears that the maintainer
> of the Debian wxPython is not building packages for both Python 2.3 and
> 2.4. The maintainer of the Ubuntu wxPython package apparently is.

As far as I know, the maintainer of the wxPython package is the same (Ron) and 
Ubuntu just uses the upstream wxPython from Debian. However, I see above that 
you are referencing wxPython 2.4 and not 2.6. It is very possible that for 
wxPython 2.4, there is only a Python 2.3 package.

wxPython 2.4 is obsolete. If possible, wxPython 2.6 should be used. But, I 
don't 
know if it is available for Python 2.4 under Debian (or Ubuntu, for that 
matter).

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-05 Thread Paul McNett
[EMAIL PROTECTED] wrote:
> Python is the superior design, today.  But, like Betamax tape format,
> Python isn't mainstream yet.  And, sadly, maybe it never will be.  I
> want that changed.  I want Python to take over the world so I don't
> have to beg my next boss to let me use it.  And if adding an optional
> "dumbed-down" format will help then that might be an improvement in the
> big picture.  

I couldn't disagree more. I most certainly do *not* want Python to take over 
the 
world. I want .NET and Java to prevail, so that large companies with money to 
throw away at such technologies will continue to do so, and so that I can still 
fly in under the radar to my small clients and be able to provide them with the 
simplest solution that works at a price they can afford and a price that I can 
live on. Having .NET and Java in the world makes me into more of a hero when I 
can swoop in and get the real business problem solved using Python.

Now, say Python were to usurp everything else and become the dominant language. 
Everyone would learn Python. Python would become all the rage and get all the 
hype. Sun, Oracle, Microsoft, IBM, Apple, and SCO would all evangelize on their 
new Python initiatives. Microsoft would attempt to release their version with 
just a few non-standard things added on. Sun would sue them for not sticking 
with standards. Books and articles would be written. Middle-level management 
would start identifying places that Python is deficient in their eyes. CIO 
Insight would start making recommendations. Everyone would be pumping so much 
energy into so many different places that, like Java, Python would stall out 
and 
be consumed by its own hype, and the programmers that made Python what it is 
would burn out on it (read: they'd be busy counting all their stock options).

Plus, there would now be a deluge of Python programmers in the market place, 
competing with my billing rate.

No, I like Python just where it is, thank you very much. If someone doesn't 
want 
to give Python a second look because of their own bigoted ideas, I say Python 
doesn't want that type of person to begin with. Perhaps that sounds a bit 
elitist, but if people would just put their preconceptions aside, they'd 
quickly 
realize that Python really does get block indentation (and a whole host of 
other 
things besides) right.

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-05 Thread Paul McNett
Christopher Subich wrote:
> [EMAIL PROTECTED] wrote:
> 
>>>From "The Design of Everyday Things", docs are a sign of poor design.
>>Even a single word, such as the word "Push" on the face of a door, is
>>an indication that the design can be improved.  Please, rethink the
>>design instead of trying to compensate with more documentation.  
> 
> 
> This quote, with a naive reading, would seem to imply that "needing 
> documentation is evidence of bad design."  I think we can all agree that 
> this interpretation is ludicrous: the only programming language, for 
> example, which does not need documentation is the natural language, and 
> that contains so many ambiguities that humans often get instructions wrong.

Indeed, there is only one user interface that needs no documentation whatsoever.


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: Tabs bad

2005-12-06 Thread Paul McNett
Björn Lindström wrote:
> Paul Rubin <http://[EMAIL PROTECTED]> writes:
> 
> 
>>[EMAIL PROTECTED] (Björn Lindström) writes:
>>
>>>Actually using tabs for eight spaces and then filling out with spaces to
>>>the correct indentation is the convention for Emacs Lisp. Of course,
>>>since everyone coding Emacs Lisp does it with the same editor, it's no
>>>problem.
>>
>>The variable `indent-tabs-mode' controls this.  I like no tabs.
> 
> 
> Same here. It's still the convention for Emacs code, regrettably.

I don't use Emacs, I do indent with tabs, and I do fill in the extra spaces of 
continuation lines with spaces. Therefore, I break all the commandments and do 
everything wrong. ;)

FWIW, I've long struggled with my opinion on tabs versus spaces. When I started 
programming in 1995, tabs seemed the logical choice because I was using 
different editors all the time and I could tell each editor how many spaces to 
give each tab. But then as I started reading more people's code I started 
seeing 
patterns in source code that I couldn't emulate using pure tabs. This comes 
down 
to horizontal "lining up" continuation lines with prior lines. Examples:

select customer.cfirst,
customer.clast
   from customer
  where customer.cstate in ("CA", "OR")
  order by customer.clast

 win = dabo.ui.dDialog(self, NameBase="frmRulesDialog",
   Caption="Minesweeper Rules", 
SaveRestorePosition=True,
   Centered=True, Modal=False)

Everyone that was writing "beautiful code" like this was using spaces only. So 
I 
switched. But it was a real PITA to not be able to use any old editor, only 
ones 
that could set how many hard spaces to make for each hard tab. And, I had to 
remember to make that setting because I prefer 2 spaces per tab.

So now I'm back to tabs for indentation and spaces for lining up continuation 
lines. Example:

win = dabo.ui.dDialog(self, NameBase="frmRulesDialog",
  Caption="Minesweeper Rules", 
SaveRestorePosition=True,
  Centered=True, Modal=False)

(if that didn't come over email correctly, that is one tab for indentation on 
all three lines, followed by several spaces on lines 2 and 3 for getting the 
arguments lined up with the previous line.)

I've been reluctant to admit to doing this since it violates the NEVER MIX TABS 
AND SPACES commandment, but there you go. I found a way to reconcile the best 
of 
both worlds, because let's face it, tabs do make slightly more sense.

Finding out that Emacs has been doing this by default makes me feel better 
about 
admitting this publicly.

There are definitely issues with mixing whitespace like this, especially is 
someone is encountering it without understanding it. But Python handles it just 
fine.


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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

Re: difficulty connecting to networked oracle database

2005-07-21 Thread Paul McNett
yahibble wrote:
> Now, I am no Python expert but I have dabbled and I have spent a
> couple of days with another engineer unsuccessfully installing oracle
> drivers for MS ODBC on the win XP machine.
> 
> It looked to me like ODBC was the best way to get a (free) python
> module to upload data to an oracle database table. Aside from
> installing oracle clients to ODBC being a pain, I would like to
> consider other ways to connect.
> 
> Has anyone had experiences with Python connecting to oracle from Win
> XP? I have searched the 'net for various modules and discussions but
> have no success thus far.

I don't have specific experience with Oracle and Python, but I do know 
that using Python's DB-API is usually the best way to go. For Oracle, 
everyone seems to be using cx_oracle, a Python package freely 
downloadable from:

http://www.computronix.com/utilities.shtml

ODBC isn't really the best solution for Python programs.

-- 
Paul McNett
http://paulmcnett.com

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


Re: Separation of Code in CGI App

2005-07-22 Thread Paul McNett
Rob Cowie wrote:
> So, do I separate out whatever code I want to into .py modules, then
> have the cgi script import them, and utilise them as required?

Bingo!


> If so, do I need to put these modules somewhere described in the System
> Path? 

Put them in the same directory, and you don't have to worry any more 
about it. You can get more advanced if you want by putting your modules 
into a "package", which is just a directory with a __init__.py file - 
see the docs at python.org.


> Can I modify the PATH at runtime to point to my modules? How?

If you want to have them in a different directory, and the directory 
isn't already in sys.path, then just issue, from your main script, 
before your import statements:

import sys
sys.path.insert(0, "/path/to/your/modules")


> Cheers for being patient!

Welcome to Python! Being new to it, you may want to consider having 
someone review your code before putting it on the public internet, 
simply because there are lots of opportunities for inadvertantly 
providing backdoors (Python is powerful). This is especially true if you 
let your users type into a text box, or if you do dynamic database 
queries, or both.

Also, have you run through the tutorial on python.org?


-- 
Paul McNett
http://paulmcnett.com

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


Re: Separation of Code in CGI App

2005-07-22 Thread Paul McNett
Rob Cowie wrote:

> So to be clear, if a .py module is in the same directory as my python
> cgi script, I can import it thus 'import XXX.py'?

Not quite. If you had a XXX.py, XXX.pyc, and/or XXX.pyo in the same 
directory as your Python cgi script, you'd import it by issuing:

import XXX


-- 
Paul McNett
http://paulmcnett.com

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


Re: Wheel-reinvention with Python

2005-07-31 Thread Paul McNett
Torsten Bronger wrote:

> Terry Hancock <[EMAIL PROTECTED]> writes:

>>I know I'm diving into this conversation late, and I haven't read
>>the whole thread, but has someone yet mentioned the "anygui"
>>project?  This has stalled, but it was IMHO a good idea.

> I don't know exactly why this project died, but I'd start with a
> Pythonic variant of wxPython.  I've read many discussions about the
> people who didn't like the wxPython's C++ style, so there are
> chances to get fellow developers and users.  You must reach the
> critical mass quickly in order to get a survivable project, and
> being not too far away from an existing one is a good stating point.
> 
> Possibly Dabo manages such a thing.

Dabo does indeed begin to manage a pythonic wrapper to wxPython. When we 
originally began Dabo, we envisioned wrapping all the major UI toolkits, 
such as Tkinter, PyQt, wxPython, curses, and even http. You would define 
your subclasses of the Dabo base widgets, and then at app startup you'd 
specify which UI library you wanted to use. As long as your own code was 
clean of UI-library-specific references your UI could render on any 
supported library.

I got some minimal proof-of-concept work done about a year ago, to show 
that the same code could render on wxPython as well as on Tkinter. But, 
unless we get a lot more help, developer or financial, I think it's safe 
to say Dabo wraps wxPython, and that's it.

Now, that was only one part of the original Dabo vision, and the other 
parts of the vision may actually add too much baggage and bloat for 
people just interested in the UI aspect. Dabo also provides an 
Application object, a database layer, and a business object layer. Ed 
and I have discussed the possibility of ripping out the UI layer and 
putting it into a completely separate project for the purpose of getting 
more wxPython users interested. It wouldn't be all that hard to do, 
because we've kept all the UI code separate from the the other stuff by 
design.

If we ever get to the "critical mass", we can start adding wrappers for 
other libraries, but this vision is always going to be limited by a 
"lowest common denominator" factor. But one of the other things we've 
done with Dabo is keep access to the base UI-library functionality if 
needed. IOW, say you are developing an app that you know will always use 
wxPython. For the most part, you will be able to use pure-Dabo 
properties, events, and methods to implement your UI. But, perhaps there 
is something more low-level that you need to do, such as using a DC to 
draw something on top of a widget, and Dabo doesn't wrap that. Dabo's UI 
classes are mixins to wxPython's, and you could just import wx manually 
to get access to the wx namespace and do whatever you want. While this 
goes against Dabo's vision on an idealistic level, it satisfies your 
needs at a practical level. You can benefit from Dabo's ease of use 80% 
of the time, and resort to doing lower-level stuff only when needed.

As far as anygui goes, we only became aware of it after significant work 
had already gone into Dabo. I have looked at it and I think there may be 
possibility for some mindshare between the projects, but it is, alas, 
always easier to reinvent the wheel yourself than to try to design by 
committee.

-- 
Paul McNett
http://paulmcnett.com

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


Re: Wheel-reinvention with Python

2005-07-31 Thread Paul McNett
Torsten Bronger wrote:
> Hallöchen!
> 
> Paul Rubin <http://[EMAIL PROTECTED]> writes:
> 
> 
>>Ed Leafe <[EMAIL PROTECTED]> writes:
>>
>>
>>>But since UIs are incredibly complex beasts, we've chosen to
>>>tackle one at a time, and after looking at them all and
>>>considering different issues, we chose wxPython as the best
>>>toolkit for creating platform-independent apps.
>>
>>How on earth did you decide that, since tkinter actually runs out
>>of the box when you install Python on most platforms, and wxPython
>>doesn't?
> 
> 
> I can't really understand your hostility towards non-Tkinter
> toolkits.  In the case of wxPython, it's part of SUSE, which is
> probably also true for Fedora and Mandriva.  Installing is as easy
> as selecting a checkbox.  This covers a very great deal of Linux
> users.  On Windows you have to call an exe file.

I'm at a loss too: on Debian, it is a simple:

sudo apt-get install wxpython

On Redhat, you download the RPM and:

rpm -i

On Windows and Mac, you download the package and run through the wizard.

Admittedly, installing from source is more difficult than any other 
project I've found, but still doable.

Tkinter was a contender, but unfortunately while it is easy to use, it 
doesn't provide a modern GUI look and feel. That was a showstopper, at 
least for me.

-- 
Paul McNett
http://paulmcnett.com

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

Re: Dabo in 30 seconds?

2005-08-01 Thread Paul McNett
Terry Reedy wrote:
> "Ed Leafe" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]

>>I'm serious here: I want to know what people consider acceptable for a
>>software package that relies on other packages.

> To me, acceptability depends on the audience.  Do you want to limit Dabo to 
> professional developers comfortable with sometimes cryptic traceback 
> messages or do you want to include people using Python as part of other 
> activities?

My concern with putting another layer on top of Python's excellent 
traceback mechanism is that we could screw up and hide important 
exceptions, or otherwise make it harder for the seasoned Pythonista to 
get to the source of the issue. Nothing beats those tracebacks, ugly 
though they may seem to a newbie... perhaps we need both methods, and to 
default to the "nice" error handler.

Your idea of checking for common missing pieces or misconfigurations on 
startup is a great idea though. Also, we do already provide for 
information and error logs, which get directed to stdout and stderr by 
default. Perhaps we just need to give slightly higher-level control of 
them, so that an individual developer can "set it and forget it" for 
each individual app. There are other settings as well, such as event 
logging, that are useful during testing - we should consolidate all 
these options into a setup screen of some sort. All in good time!

-- 
Paul McNett
http://paulmcnett.com

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


Re: Wheel-reinvention with Python

2005-08-01 Thread Paul McNett
Devan L wrote:
> If you're creating a new instance of your dApp(I assume its a class)
> with no arguments, then effectively your just creating a default
> program which is already defined in the dabo module. If you could write
> it in a few, short lines of code by defining a new class, then you
> might have something there.

import dabo
app = dabo.dApp()
app.UI = "wx"

class MyTextBox(dabo.ui.dTextBox):
 def initProperties(self):
 self.Width = 200
 self.Value = "Planet Earth is blue"

class MyForm(dabo.ui.dForm):
 def afterInit(self):
 self.addObject(MyTextBox)
 def initProperties(self):
 self.Caption = "Ground Control To Major Tom"

app.MainFormClass = MyForm
app.start()



-- 
Paul McNett
http://paulmcnett.com


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


Re: Wheel-reinvention with Python

2005-08-01 Thread Paul McNett
Mike Meyer wrote:
> Paul McNett <[EMAIL PROTECTED]> writes:
> 
>>On Windows and Mac, you download the package and run through the wizard.
> 
> Which package? I'm looking at the sourceforge download site, and don't
> see any packages for Python 2.4 on OS X 10.4. In fact, I don't see any
> packages for 10.4 at all. IIRC, they didn't have a 2.4 package last
> time I looked. I may download the 10.3 one and see if it works.

I can confirm that the 10.3 one works on Tiger. I think that Robin 
doesn't have a Tiger machine to build on yet, which is why there's no 
package for it. Perhaps more information is at the wxPython download 
site (not the Sourceforge one) at:

http://wxpython.org/download.php

>>Admittedly, installing from source is more difficult than any other
>>project I've found, but still doable.
> 
> Well, I've got a long history of installing things from source - going
> back to v6. On OS X, I like the darwin ports stuff, so I tried that:
> 
> % sudo port install wxpython
> 
> It blew up trying to compile wxpython. The multitude of dependencies
> all seemed to build find. Building wxpython from the source
> distribution by hand doesn't seem to fair any better.

To build wxPython from source, you really need to follow Robin's 
detailed instructions in BUILD.txt, located somewhere in the source tree 
(I have to look for it every time, but I think it is in 
wxSrc/wxPython/docs/BUILD.txt). It isn't difficult but there's more to 
it than the standard ./configure;make;make install.

> P.S. - no, this isn't just a theoretical exercise. I want to play with
> THE, and that's been rewritten from it's Mac-only version to use the
> Python wxWidgets wrapper. It's mostly curiosity, so I'm not willing to
> work very hard on it. If the dependencies will build out of the box -
> cool. If not - I have lots of other things to do.

I think you'll find that wxPython installs perfectly on Tiger using the 
package provided. Indeed, the only really painful platform to install 
wxPython on is Linux, where you pretty much need to build from source if 
you want the latest and greatest.

-- 
Paul McNett
http://paulmcnett.com

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


Re: Dabo in 30 seconds?

2005-08-02 Thread Paul McNett
Fernando Perez wrote:
> 
> 
> You may want to steal the crash handling code from ipython.  In order to
> address this kind of problem, ipython sticks an exceptionally verbose
> traceback printer into sys.excepthook.  If ipython ever crashes, the user gets
> a LOT of info, and it's all packaged ready to go, to be emailed to me.  Here's
> an example of the result (I stuck 1/0 inside to force the crash):

[snip]

> This approach has worked very well for me over the years, and these crash
> report emails have become fortunately rather rare as of late :)
> 
> If you are interested, just get ipython and grab the files for this, it's all
> BSD licensed.  You can also browse the SVN repo here if you want to look at
> the code:
> 
> http://ipython.scipy.org/svn/ipython/ipython/trunk/IPython/
> 
> The relevant files are ultraTB.py and CrashHandler.py.

Thanks Fernando, consider your excellent code stolen! :) I'll probably 
make a flag that defaults to ultraTB but that can also be set to leave 
sys.excepthook as-is. Best of both worlds!

I've done things like this in the past, in my own Visual Foxpro 
framework. In that situation, I had enough control over the deployment 
to also ship a small smtp client, and automatically email the error 
without requiring any interaction at all. Clients were impressed when 
I'd already have a fix for the problem before they even notified me of 
the issue!

-- 
Paul McNett
http://paulmcnett.com

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


Re: Wheel-reinvention with Python

2005-08-03 Thread Paul McNett
Mike Meyer wrote:
> Mike Meyer <[EMAIL PROTECTED]> writes:
> 
>>>I think you'll find that wxPython installs perfectly on Tiger using
>>>the package provided. Indeed, the only really painful platform to
>>>install wxPython on is Linux, where you pretty much need to build from
>>>source if you want the latest and greatest.
> 
> 
> FWIW, Tiger ships with wxPython pre-installed.

Yes, but it's an older version... isn't it 2.4?

-- 
Paul McNett
http://paulmcnett.com

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


Re: Import question

2005-08-09 Thread Paul McNett
ncf wrote:
> In file A, I have an instance of a class and then I import file B
> (import fileB as fb). In file B, I need to access file A's class
> instance. Is there anyway I can do this? (I hope that was descriptive
> enough :\)

Let's see...

# -- fileA.py
class Test(object): pass

myInstance = Test()

import fileB as fb
fb.myInstance = myInstance
fb.test()

# -- fileB.py
myInstance = None

def test():
print "myInstance is %s" % myInstance

if __name__ == "__main__":
test()

# -- now to the command line to test:
[EMAIL PROTECTED]:~/projects/dabo/dabo/ui/uiwx $ python fileB.py
myInstance is None
[EMAIL PROTECTED]:~/projects/dabo/dabo/ui/uiwx $ python fileA.py
myInstance is <__main__.Test object at 0xb7dfcf6c>

Is this what you want? BTW, what you call "files", we refer to as 
"scripts" (if run) or "modules" (if imported).

-- 
Paul McNett
http://paulmcnett.com

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


Re: Default function arguments behaving badly

2005-08-24 Thread Paul McNett
[EMAIL PROTECTED] wrote:

> I'm having some trouble with a function I've written in Python:

> def myFunction(l1,l2,result=[]):
[snipped rest of function and explanation of what it does]

> Does anyone know what is going on here? Is there an easy solution?

It shined out like a supernova. It has to do with mutability of certain 
Python objects (e.g. dicts and lists) and the fact that Python binds the 
default arguments only once. So, when your function is defined, python 
binds the name "result" to the value []. Then, your function runs the 
first time using that original binding. The second time, it still uses 
the original binding which, because lists are mutable, still contains 
the prior list. Etcetera.

The solution is to never assign mutable objects to default arguments. 
Instead, assign to None, like:

def myFunction(l1, l2, result=None):
if result is None:
result = []

Others will certainly post links to the python docs that explain this.

-- 
Paul McNett
http://paulmcnett.com

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


ANN: Dabo 0.4.1

2005-08-31 Thread Paul McNett
We are happy to announce the release of Dabo 0.4.1, available for
download from:

http://dabodev.com/download

Dabo is a framework for developing 3-tier database applications, and
comes with database wrappers for MySQL, PostgreSQL, Firebird, and
SQLite. It wraps the wxPython GUI toolkit, making it easier to use and
more polymorphic, providing a nice property interface to the controls.

In addition to the main dabo-0.4.1 package, there are also updated
downloads for dabodemo-0.4.1 and daboide-0.2.1.

There have been numerous improvements in Dabo over the past few weeks
since 0.4, summarized here:

Improved test framework for uiwx. Now you can run ui/uiwx/test.py and
get almost all of the dabo controls in one form, and they are the same
tests that you get when you run an individual control directly.

Factored out the saving/restoring of user settings out of dApp into
the separate dUserSettingProvider class, which can be subclassed or
overridded by the developers. Added properties UserSettingProvider
and UserSettingProviderClass to dApp.

Dabo user settings are no longer saved to .userSettings.ini in the app
directory, but are saved to the user's home directory (in ~.dabo/) or
if on Windows, in /Application Data/Dabo/.

Support for SQLite added. As of this moment, Dabo supports several major
open-source database backends: MySQL, PostgreSQL, Firebird, and SQLite.
Next on the list should be Oracle, Sybase, and MS-SQL.

Started work implementing a Quick Report in the datanav library, which
replaces the old HTML Print Preview. This uses the fledgling Dabo Report
Writer to create a PDF rendition of the dataset.

Added new property for all controls: StatusText. When set, and when the
form has a status bar, that text will show in the form's status bar when
the mouse enters the control.

Expanded the dabo.ui.strToBmp() function to accept an optional scale
factor or width/height values. If they are passed, the returned bitmap
image is sized to those values.

Added an optional parameter to the bizobj and cursor's getDataSet()
method. If you send a list of field names, only those fields are returned.

Fixed some lingering bugs in the dabo.ui.uiwx package and the datanav
lib. dWizard works better now. Improved dGauge, dLine, dBox, dRadioBox,
dListBox, dToolBar, and dSizers.

Added simple decimal support to dTextBox.

Work continues on dGrid, specifically dColumn is now better worked
into the "Dabo Way".

Added dabo.trace() function, that will drop you into pdb.

dConnectInfo reworked to have better property names.

Removed dependency on PIL and reportlab from Dabo. These are dependencies
still, but only if you try to run a report.

Added dabo.lib.StopWatch.StopWatch class, which is a light Python
stopwatch with start(), stop(), reset() methods and Value property.

This is a partial list. Both Ed and Paul have been very busy with Dabo
since 0.4 a few weeks ago. Lots of bugfixes and enhancements were made,
and we encourage everyone to upgrade.

---
In addition, we'd like to note that the minesweeper game in dabodemo has
been greatly improved, and also the addition of the card game of
montana. The development of these games are helping us iron out user
interface issues that otherwise may have gone unnoticed.

The AppWizard in daboide/wizards has also been updated to produce even
better generated applications, ones that give the developer a starting
structure that is relatively easy to tweak, modify, and augment.


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com



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


Re: PyGTK or wXPython?

2005-09-13 Thread Paul McNett
Jarek Zgoda wrote:

> I would use wx, if it wasn't so dog slow on linux. Qt and GTK are much
> faster, but each one has disadvantages. Finally, you get 3 GUI toolkits,
> of which each claims to be "cross-platform", but each is working at
> acceptable level of WTF only on one system (wx on Windows, Qt and GTK on
> linux) and the most appealing (Qt) has no free version for Windows.

I must say, I haven't found wx to be slow on Linux at all. Slow on Mac, 
yes, but faster on Linux than on Windows (and getting much much better 
on Mac). The exception to this is the StyledTextControl, which is by far 
much faster on Windows, and with lots of styled text dog-slow on Linux.

Wx does use the native underlying toolkit for the platform (Qt is 
owner-drawn), which can cause some platform inconsistencies.

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: wxGrid

2005-02-28 Thread Paul McNett
Gensek wrote:
I have a grid. I want to sort it when a column label is clicked. I know
about the EVT_GRID_LABEL_LEFT_DCLICK event, but that is not enough. I
do not merely need to know that a label was clicked. I need to know
which label was clicked. I do not know how to do that. I suspect you
might know. I request that you tell me.
Please see:
http://wiki.wxpython.org/index.cgi/DrawingOnGridColumnLabel
It tells you how to draw a sort indicator on the clicked header, which 
involves first figuring out which header was clicked. As you've found, 
the entire header region is one wxWindow, not one per column, which does 
make it a bit more difficult to sort out which column header was 
clicked. This sample does not go on to show you how to actually do the 
sorting, however.


I also wish to know some other things: how to find out the location of
a mouse pointer in a wxWindow (or at least the frame), 
Bind a function to the wx.EVT_MOTION event, and then call GetPosition() 
of the event instance, which returns a (x,y) tuple of the mouse position 
at the time the event was generated. x and y are relative to the window 
that emitted the event.


and how to
change the color of a single specified pixel in a bitmap.
I don't know how to do this, but I'd take a look at the docs for 
wxBitmap for starters.


I use Python 2.3, wxPython 2.4.2.
You should upgrade to wxPython 2.5.3 (2.5.4 is around the corner 
though). If you have a bunch of code already written for 2.4, you'll 
want to upgrade carefully and refer to the migration guide at 
http://wxpython.org first. Otherwise, if you are just starting with 
wxPython, trust me you definitely want to upgrade ASAP - a lot of bugs 
have been fixed and new features added since 2.4.2, and wxPython experts 
will be better able to help you if you use a recent version...

Also, you may find more and better help by joining the wxpython-users 
list - you can find a link at http://wxpython.org.

--
pkm ~ http://paulmcnett.com
--
http://mail.python.org/mailman/listinfo/python-list


How to launch pdf viewer on Mac?

2005-03-10 Thread Paul McNett
Hi,
On Windows, os.startfile() does what I want:
os.startfile("myDocument.pdf")
That launches the default PDF viewer on the system in a separate 
process. Perfect.

On Linux, I understand that there really isn't a standard for 
determining a default application for a given file type (indeed, there 
may not even be a windowing system installed), so on that platform I've 
resorted to:

os.system("xpdf myDocument.pdf &")
But on Mac, what do I do? The user may prefer Adobe Acrobat Reader, the 
native Preview utility, or some other viewer. Actually, at this point 
I'll settle with figuring out how to launch the native Preview utility, 
but the ideal solution would let the user preference as set at the Mac 
system level determine the viewer.

While my question is "how do I launch a pdf viewer on Mac" I'll take 
constructive criticism on how I've solved this for Windows and Linux as 
well...

Thanks! See you at PyCon!
--
pkm ~ http://paulmcnett.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Script suddenly stops

2014-05-30 Thread Paul McNett

On 5/29/14, 7:47 PM, Chris wrote:

I'm trying to read ten 200 MB textfiles into a MySQL MyISAM database
(Linux, ext4). The script output is suddenly stopping, while the Python
process is still running (or should I say sleeping?). It's not in top,
but in ps visible.


Does it stop in the same place every time? How long are you waiting 
before giving up? Is it at all possible that it is the MySQL side that 
is blocking?



Why is it stopping? Is there a way to make it continue, without calling
"kill -9", deleting the processed lines and starting it again?


One thing to try (maybe, depending on whether it still fits into your 
requirements for a database transaction) is to increase the number of 
rows inserted before each commit.



[1] http://pastebin.com/CxHCA9eB


It won't have any bearing, but those globals aren't necessary...


Paul
--
https://mail.python.org/mailman/listinfo/python-list


Re: Suds and Python3

2014-05-31 Thread Paul McNett

On 5/31/14, 11:36 AM, tokib...@gmail.com wrote:

Suds is defacto python SOAP client, but it does not mainte recent few years. 
Why?


Is it really the defacto? It seems like I've heard more about 
pysimplesoap, and looking at GitHub there have been commits in the past 
4 days.


As far as why it hasn't been maintained, you could write and ask the 
authors directly.


In general, SOAP has been falling out of favor over the past half decade 
at least because of its relative heaviness next to, e.g. RESTful web 
services usually using JSON instead of XML. Way, way simpler and more 
fun to do.


That said, SOAP will be around for a long time and if you need to do it, 
you want a good library for it.


I don't have direct experience, but I did do cursory reviews of a 
handful of the SOAP libaries listed here in the python wiki:


https://wiki.python.org/moin/WebServices

And from what I can tell without actually trying any of them, 
pysimplesoap feels like the best option currently.



I want to use SOAP and Python3. How do it?


If it were me, I'd install each of the libraries listed on the wiki page 
and make a matrix of features desired, make up a suite of unit tests to 
test those features, and then run each of them through the suite to see 
how they stack up. Also consider how "alive" the project is, and how the 
project's bug tracker is maintained, look at their forum, etc.


Paul
--
https://mail.python.org/mailman/listinfo/python-list


Re: Not Responding When Dealing with Large Data

2014-06-18 Thread Paul McNett

On 6/18/14, 10:20 AM, cutey Love wrote:

I'm trying to read in 10 lines of text, use some functions to edit them and 
then return a new list.


How is it that you are opening the file, and iterating the contents?


The problem is my program always goes not responding when the amount of lines 
are a high number.


What do you mean, "goes not responding"? What environment are you 
running in? Windows and IDLE?



I don't care how long the program takes to work, just need it to stop crashing?


Note that "not responding" isn't the same as crashing. If your program 
crashed, it would likely print on your terminal something like:


Traceback (most recent call last):
... lots of lines including useful information about the problem

or

Segmentation Fault

If it just goes "not responding" for a while in your tight loop, it 
could simply mean just that: your IDE or whatever is focusing so hard on 
running your program that there aren't any cycles to say "still here" to 
the OS, so the OS has no clue what's going on and says to the user "not 
responding".


Have you waited to see if it ever completes?

Paul

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


Re: Generate Single PowerPoint from two powerpoints using pywin32(python)

2014-06-18 Thread Paul McNett

On 6/16/14, 11:20 PM, Jaydeep Patil wrote:

I have two powerpoints, which consists of images in each slide.
I need to read each powerpoint, copy images from both powerpoint & paste these 
images into output powerpoint side by side.

How should i do thism using python?
The repoisition of shapes seems to be difficult.


This seems like the wrong forum to ask this. Whatever the right 
Powerpoint calls are to accomplish this, it has nothing to do with 
Python. Well, you are making the calls via Python but the content of the 
calls aren't python.


Back in the old days (it's been over a decade since I've worked with 
Microsoft Office using COM automation) when I needed to figure out how 
to programatically manipulate a Powerpoint slide or Excel spreadsheet, 
my general flow was:


1) turn on the macro recorder in Office.
2) do the operation that needs doing, using the Office UI.
3) save the macro.
4) set up the situation again, and this time play back the macro to make 
sure it works.
5) convert the macro code into whatever is needed in the client 
programming language (usually just wrapping the actual macro lines of 
code into strings passed using a pywin32 function)

6) test running the situation with the calling client programming language.

Frankly, I'm not sure COM automation is the current way to interact with 
Microsoft stuff, but surely by querying other forums (Microsoft Office 
automation forums should exist, I'd think) on how to do #1-3 above would 
get you halfway. Then you could ask here about how to use pywin32 (or 
whatever) to communicate with Powerpoint to do the work.


Does that make sense?
Paul


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


Re: Not Responding When Dealing with Large Data

2014-06-18 Thread Paul McNett

On 6/18/14, 3:32 PM, cutey Love wrote:

Hi, thanks for the replies,

I mean windows displays "Not responding close the program now"

How can I do it asynconistrically?

It's simple code just open file, loop through line by line and do some 
comparons with the string.


To get anything better from us than we've already given, you must tell 
us your environment and show us some code.


Paul

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


Re: Python Fails to Write to File

2014-06-18 Thread Paul McNett

On 6/18/14, 4:03 PM, cutey Love wrote:

I'm trying to write data to a text file

But I'm getting the error:

TypeError: invalid file: <_io.TextIOWrapper


Always better to err on posting too much context (the entire traceback) 
than too little.




Code is

def saveFile():
 file_path = filedialog.asksaveasfile(mode='w', filetypes=[('text files', '.txt')], 
defaultextension=".txt")
 fo = open(file_path, 'w')


I used Google (searched on "filedialog.asksaveasfile") to realize that 
you are likely using Tkinter. I then used Google to find out the API for 
filedialog.asksaveasfile() and I found that it returns the ALREADY OPEN 
FILE for you to write to, not the name of the file you are writing to.


Referring to that same documentation, I see there's another function you 
are probably more interested in: filedialog.asksaveasfilename(). Then, 
you can open the file, write to it, and close it and be in control of 
every step. Not sure which is preferable, though, as I have no (recent) 
Tkinter experience.





 for e in myList:
 fo.write(e)


 fo.close()


You should use a context manager to open, write to, and close files. 
Such as:


with open(file_path, 'w') as fo:
for e in myList:
fo.write(e)


The file is being created if not already present but no data is written


filedialog.asksaveasfile() was opening it for you. It was being closed 
automatically when file_path fell out of scope (after the exception 
caused by your fo = open(file_path, 'w') line.


My response was intended to help.
Paul

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


Re: What should i do

2014-06-27 Thread Paul McNett

On 6/27/14, 2:19 AM, suburb4nfi...@gmail.com wrote:

Hello I finished the codeacademy python course a week ago and my goal is to 
start developing websites (both back and front end) ,my question is do i start 
the web dev tuts and learn the holes of knoledge on the go or continue to learn 
python?


In my opinion if you want to start developing both front and backend of 
websites, then you should start developing a "full-stack" web 
application. You'll stumble and have to redo things along the way, but 
there's no better way to learn.


1) Get a Linux host with root access, like from Rackspace cloud. You are 
only charged while it is switched on. If you leave it on for a month 
you'll owe maybe $16.


2) Install python, virtualenv, pip, and a web framework. Starting with 
flask would be an excellent choice.


3) Install a database backend. Starting with PostgreSQL would be an 
excellent choice.


4) Implement the polling app from the Django tutorial, or maybe you have 
your own idea of a simple app to make.


5) Learn CSS and throw in some javascript to make it pretty.

6) Push your commits to GitHub along the way.


Do all of this and I can't promise how long it will take, but I can 
promise you'll be well on your way to becoming a strong web developer.


Paul
--
https://mail.python.org/mailman/listinfo/python-list


Re: What should i do

2014-06-27 Thread Paul McNett

On 6/27/14, 11:12 AM, alister wrote:

On Fri, 27 Jun 2014 08:18:24 -0700, Paul McNett wrote:


On 6/27/14, 2:19 AM, suburb4nfi...@gmail.com wrote:

Hello I finished the codeacademy python course a week ago and my goal
is to start developing websites (both back and front end) ,my question
is do i start the web dev tuts and learn the holes of knoledge on the
go or continue to learn python?


In my opinion if you want to start developing both front and backend of
websites, then you should start developing a "full-stack" web
application. You'll stumble and have to redo things along the way, but
there's no better way to learn.

1) Get a Linux host with root access, like from Rackspace cloud. You are
only charged while it is switched on. If you leave it on for a month
you'll owe maybe $16.

Better yet host internally on your own Linux box
Even a Raspberry pi for <£45 (inc case PSU & sd card) could do this if
you don't have a spare PC to use.

you don't want a development system exposed to the public internet anyway
(unless you want to become Nicos Mk 2)


Well, that's part of the experience too. :)  Seriously, set up the 
firewall to only allow port 80 from your address, etc.


Installing VirtualBox and Ubuntu on your local system is probably the 
better way to go at first, agreed.


Paul


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


Re: I need an idea for practise!

2014-07-17 Thread Paul McNett

On 7/17/14, 12:30 PM, Rick Johnson wrote:

You know, you would fit in nicely in the American public
school system, since American teachers are not only free of
the requirement of "teaching", they are actually*COMPELLED*
not to do so by the greedy unions.


Hi Rick,

I know a lot of American public school teachers, and they are among the 
hardest-working people I've ever encountered. I have no clue what you 
mean about them being free of the requirement to teach.


Do you find that insulting people achieves your goals?

Paul
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help with super()

2006-01-12 Thread Paul McNett
David Hirschfield wrote:
> Is there a way to get what I'm after using super()?

Probably.


> The idea is that I could have a chain of subclasses which only need to 
> redefine _v, and getting the value of v as a property would give me back 
> the full chain of _v values for that class and all its ancestor classes.

Does this work? :

class A(object):
   _v = [1,2,3]

   def _getv(self):
 ret = []
 mroList = list(self.__class__.__mro__)
 mroList.reverse()
 for c in mroList:
   print c, ret
   if hasattr(c, "_v"):
 ret += c._v
 return ret

   v = property(_getv)


class B(A):
   _v = [4,5,6]

b = B()

print b.v


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: Help with super()

2006-01-12 Thread Paul McNett
David Hirschfield wrote:
> I tried that and super(B,self), but neither works.
> 
> Using super(A,self) in the _getv(self) method doesn't work, since the 
> super() of A is "object" and that doesn't have the v property at all.
> Not sure why you say that using self.__class__ is wrong as the first 
> argument to super(), it should be the same as using the class name 
> itself - both will result in  or whetever self is an 
> instance of.
> 
> I still don't see a way to accomplish my original goal, but any other 
> suggestions you might have would be appreciated.

Your basic problem is that property fset(), fget() and friends are defined at 
the class level, not at the instance level. So if you want to override the 
setter of a property in a subclass, you pretty much have to redefine the 
property in that subclass. And therefore, you also have to redefine the getter 
of the property as well. There is no easy way to "subclass" property getters 
and 
setters.

But, there's another problem with your example code as well. You appear to 
assume that self._v is going to refer to the _v defined in that class. But take 
a look at this:

class A(object):
   _v = [1,2,3]

   def _getv(self):
 print self._v ## hey, look, I'm [4,5,6]!!!
   v = property(_getv)


class B(A):
   _v = [4,5,6]

b = B()

print b.v


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: Help with super()

2006-01-13 Thread Paul McNett
David Hirschfield wrote:
> So, the larger question is how to do anything that resembles what I 
> want, which is to have a chain of subclasses with a single attribute 
> that each subclass can define as it wishes to, but with the ability to 
> get the combined value from all the ancestors down to the current 
> subclass I access that attribute from.
> 
> Does that make any sense?

Yes, it makes sense. The trick is to not query the values using self, but to 
ask 
the class definitions for the attribute. See my second message that gives an 
example, climbing the __mro__ tree backwards.


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: Class instantiation

2006-08-23 Thread Paul McNett
Colin J. Williams wrote:
> class arSpread(object):
>def __init__(self, fileId= None, ar= None):
>  if fileId:
>if ar is not None:
>  print fileId
>  self.connect(fileID, mode= 'r')   # open sheet in the read mode
>else:
>  self.connect(fileID, mode= 'w')   # open the sheet in the 

'dOH! . Change to self.connect(fileId, ...)

:)


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: .doc to html and pdf conversion with python

2006-10-14 Thread Paul McNett
Alexander Klingenstein wrote:
> I need to take a bunch of .doc files (word 2000) which have a little text 
> including some tables/layout and mostly pictures and comvert them to a pdf 
> and extract the text and images separately too. If I have a pdf, I can do 
> create the html with pdftohtml called from python with popen. However I need 
> an automated way to converst the .doc to PDF first.
> 
> Is there a way to do what I want either with a python lib, 3rd party app, or 
> maybe remote controlling Word (a la VBA) by "printing" to PDF with a 
> distiller?
> I already tried wvware from gwnuwin32, however it has problems with big image 
> files embedded in .doc file(looks like a mmap error).

I would try scripting OpenOffice from Python, using the Python-UNO bridge.

http://udk.openoffice.org/python/python-bridge.html

Once you have the pdf, use the pdftohtml to get access to the image 
elements you need.

-- 
pkm ~ http://paulmcnett.com

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


Re: Serious wxPython Error while executing..

2006-10-30 Thread Paul McNett
kath wrote:
> Hello, sorry about the lengthy message.
> 
>  I finding difficult to execute this program. The wx.Notebook i created
> is coming on the splitted frame(self.p2). How do I that. I am started
> to learn wxPython, and when I run the code, the code doesnot close
> gracefully, it throughs me an error.
> 
> "pythonw.exe has encountered a problem and needs to close.  We are
> sorry for the inconvenience"

I get a segmentation fault on Linux, after running the script, choosing
"Add new fund" from the menu, and then closing the application. I don't
get the segmentation fault if I merely start the app and close it.

> here is the code seems a bit lengthy, sorry about that.
> Please help me to find my mistake, and how do I go forward resolving
> this problem.

You actually have several problems. But, the segmentation fault appears
to be directly related to the fact that you add boxsizer to the border
sizer twice.

Another problem is that you create the notebook every single time, and
add just one page to it, but you probably want just one notebook with
one or more pages.

-- 
pkm ~ http://paulmcnett.com


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


Re: Converting Microsoft Works databases.... *shudder*

2006-11-03 Thread Paul McNett
Michael B. Trausch wrote:
> GISDude wrote:
>> Mike,
>> I totally forgot that MS Works was out there. Haven't used that one in
>> about 6 or 7 years. Honestly, your best bet is to convert to .csv or
>> some delimited .txt file. Once that is done, all your rows/columns will
>> be "nice and neat" .
>> Once that is done, (and since your client doesn't have ACCESS, try
>> MYSQL or POSTGRESQL(they are open source). They can handle A LOT OF
>> DATA, so however big your orginal DB is, you can import it to one of
>> these more than capable OS freebie Databases.
> 
> Yeah; the only thing is that I am going to have to write a solution to
> give them "easy" access to their data.  Sometimes, they just want to
> look up a row of data, but they don't want to put their data in a
> database server -- they want it on their machine so that it is "private"
> (FSVO private--it's a Windows box).

You can set up database servers that only serve to the local machine. I 
have a couple applications out there that have MySQL server running on a 
Windows box and the only client that connects is the local machine. 
However, you may find it easier and every bit as rewarding to go with 
the simpler solution: sqlite.

As far as easy access to the data, it is quite possible that Dabo could 
help you there. Once you have your data in sqlite or MySQL, the Dabo 
AppWizard can generate a basic application for you to search, browse, 
edit, and report on your records. The basic application generated can 
then be modified by you (in Python) to make it more custom and to 
enhance it as your needs grow.

sqlite information: http://initd.org/tracker/pysqlite
dabo information: http://dabodev.com

(Please note that the dabodev website is going through some scheduled 
maintenance so it may not be available when you call this weekend, but 
in any case it will be fully functional by Monday).

-- 
pkm ~ http://paulmcnett.com

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


Re: SQLwaterheadretard3 (Was: Is it just me, or is Sqlite3 goofy?)

2006-09-08 Thread Paul McNett
[EMAIL PROTECTED] wrote:
> Do you know what INNER JOIN means?
> 
> Do you know how important it is to a relational database?
> 
> Can you explain how an INNER JOIN can even work, in theory,
> with dynamic data types?

Let's stop the pissing contest and just see how it works. After all, 
this is Python and we can easily just try it out. Here's my example. 
Please tell me how this causes unexpected results, and why it isn't SQL. 
Please modify my example to get it to cause a catastrophe, and post it 
here so we can see the errors of our ways and be properly humbled.

#-- Preliminaries:
 >>> from pysqlite2 import dbapi2 as sqlite
 >>> con = sqlite.connect("test.db")
 >>> cur = con.cursor()

#-- Create 3 tables for a M:M relationship between customers
#-- and categories:
 >>> cur.execute("create table customers (id integer primary key 
autoincrement, name char)")
 >>> cur.execute("create table categories (id integer primary key 
autoincrement, name char)")
 >>> cur.execute("create table cust_cat (id integer primary key 
autoincrement, cust_id integer, cat_id integer)")

#-- Insert some test data into customer and categories:
 >>> cur.execute("insert into customers (name) values ('Ziggy Marley')")
 >>> cur.execute("insert into customers (name) values ('David Bowie')")
 >>> cur.execute("insert into categories (name) values ('Glam Rock')")
 >>> cur.execute("insert into categories (name) values ('Nuevo Reggae')")
 >>> cur.execute("insert into categories (name) values ('Male Singers')")
 >>> cur.execute("select * from customers")

#-- Take a look at the data (and retrieve the pk's):
 >>> cur.fetchall()
[(1, u'Ziggy Marley'), (2, u'David Bowie')]
 >>> cur.execute("select * from categories")
 >>> cur.fetchall()
[(1, u'Glam Rock'), (2, u'Nuevo Reggae'), (3, u'Male Singers')]

#-- Relate some customers to some categories. Note how I send strings
#-- in some places and ints in others:
 >>> cur.execute("insert into cust_cat (cust_id, cat_id) values (1, 3)")
 >>> cur.execute("insert into cust_cat (cust_id, cat_id) values (1, '2')")
 >>> cur.execute("insert into cust_cat (cust_id, cat_id) values ('2', '1')")
 >>> cur.execute("insert into cust_cat (cust_id, cat_id) values ('2', 3)")

#-- Run some queries:
 >>> cur.execute("select customers.id as cust_id, customers.name as 
cust_name, categories.id as cat_id, categories.name as cat_name from 
customers inner join cust_cat on cust_cat.cust_id = customers.id inner 
join categories on categories.id = cust_cat.cat_id order by 2,4")
 >>> cur.fetchall()
[(2, u'David Bowie', 1, u'Glam Rock'), (2, u'David Bowie', 3, u'Male 
Singers'), (1, u'Ziggy Marley', 3, u'Male Singers'), (1, u'Ziggy 
Marley', 2, u'Nuevo Reggae')]

 >>> cur.execute("select customers.id as cust_id, customers.name as 
cust_name, categories.id as cat_id, categories.name as cat_name from 
customers inner join cust_cat on cust_cat.cust_id = customers.id inner 
join categories on categories.id = cust_cat.cat_id where categories.id = 
1 order by 2,4")
 >>> cur.fetchall()
[(2, u'David Bowie', 1, u'Glam Rock')]

 >>> cur.execute("select customers.id as cust_id, customers.name as 
cust_name, categories.id as cat_id, categories.name as cat_name from 
customers inner join cust_cat on cust_cat.cust_id = customers.id inner 
join categories on categories.id = cust_cat.cat_id where categories.id = 
'1' order by 2,4")
 >>> cur.fetchall()
[(2, u'David Bowie', 1, u'Glam Rock')]

 >>> cur.execute("select customers.id as cust_id, customers.name as 
cust_name, categories.id as cat_id, categories.name as cat_name from 
customers inner join cust_cat on cust_cat.cust_id = customers.id inner 
join categories on categories.id = cust_cat.cat_id where categories.id = 
'2' order by 2,4")
 >>> cur.fetchall()
[(1, u'Ziggy Marley', 2, u'Nuevo Reggae')]

 >>> cur.execute("select customers.id as cust_id, customers.name as 
cust_name, categories.id as cat_id, categories.name as cat_name from 
customers inner join cust_cat on cust_cat.cust_id = customers.id inner 
join categories on categories.id = cust_cat.cat_id where categories.id = 
'3' order by 2,4")
 >>> cur.fetchall()
[(2, u'David Bowie', 3, u'Male Singers'), (1, u'Ziggy Marley', 3, u'Male 
Singers')]

 >>> cur.execute("select customers.id as cust_id, customers.name as 
cust_name, categories.id as cat_id, categories.name as cat_name from 
customers inner join cust_cat on cust_cat.cust_id = customers.id inner 
join categories on categories.id = cust_cat.cat_id where categories.id = 
3 order by 2,4")
 >>> cur.fetchall()
[(2, u'David Bowie', 3, u'Male Singers'), (1, u'Ziggy Marley', 3, u'Male 
Singers')]

If I have skipped the test case that will fail, please enlighten me.

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: urlopen() error

2006-09-08 Thread Paul McNett
Tempo wrote:
> Hello. I am getting an error and it has gotten me stuck. I think the
> best thing I can do is post my code and the error message and thank
> everybody in advanced for any help that you give this issue. Thank you.
> 
> #
> Here's the code:
> #
> 
> import urllib2
> import re
> import xlrd
> from BeautifulSoup import BeautifulSoup
> 
> book = xlrd.open_workbook("ige_virtualMoney.xls")
> sh = book.sheet_by_index(0)
> rx = 1
> for rx in range(sh.nrows):
> u = sh.cell_value(rx, 0)
> page = urllib2.urlopen(u)
> soup = BeautifulSoup(page)
> p = soup.findAll('span', "sale")
> p = str(p)
> p2 = re.findall('\$\d+\.\d\d', p)
> for price in p2:
>   print price
> 
> ##
> Here are the error messages:
> ##
> 
> Traceback (most recent call last):
>   File "E:\Python24\scraper.py", line 16, in -toplevel-
> page = urllib2.urlopen(u)
>   File "E:\Python24\lib\urllib2.py", line 130, in urlopen
> return _opener.open(url, data)
>   File "E:\Python24\lib\urllib2.py", line 350, in open
> protocol = req.get_type()
>   File "E:\Python24\lib\urllib2.py", line 233, in get_type
> raise ValueError, "unknown url type: %s" % self.__original
> ValueError: unknown url type: List

You were expecting u to be a url string like "http://google.com";, but it 
looks like it is actually a list. I'm not familiar with package xlrd but
cell_value() must be returning a list and not a cell value. Presumably, 
the list contains the cell value probably in element 0. Put in a print 
statement before your call to urlopen() like:

print u

You'll likely discover your error.

-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com

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


Re: detecting that a SQL db is running

2006-12-01 Thread Paul McNett
bill ramsay wrote:
> none of this matters,  all i am trying to find out is whether or not
> the local MSDE is actually running.

If it is a local MSDE then you may be able to rely on the connection
being refused if the server isn't running.

#-- begin
import socket

host = "127.0.0.1"
port = 1433  ## replace with msde_port, if it differs

s = socket.socket(socket.AF_INET)
try:
s.connect((host, port))
print "Server on %s is running" % port
except socket.error, e:
print "Server on %s appears to be down (%s)" % (port, e)

#-- end

Please note that this is untested and not very well thought through. But
try it and see if it gets you on the right track. If this isn't run
locally, you'll probably need to set the timeout low enough for the
connect call not to appear to hang before returning the timeout error.

-- 
pkm ~ http://paulmcnett.com


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


Re: Good Looking UI for a stand alone application

2006-12-18 Thread Paul McNett
Luc Heinrich wrote:
> Peter Decker <[EMAIL PROTECTED]> wrote:
> 
>> You're full of it. I routinely write GUI apps in Dabo for both Windows
>> and Linux users, and they look just fine on both platforms.
> 
> Oh, I'm sure you do. Now go try to run one of your Dabo apps on a Mac
> and see how it looks/feels... :>

It looks/feels like a native app on OS X.


> Here's a hint directly taken from the Dabo homepage: "It also suffers
> from the same display limitations on some platforms (most notably OS X),
> but these should improve as the underlying toolkits improve."

That was written a long time ago, and doesn't really apply anymore as a
lot of effort has gone into wxPython over the past three years getting
correctly interfaced to the OS X native API.

(Note to self: rewrite that (prescient) paragraph).


>> Using sizers is the key; layouts just 'look right' no matter what the native
>> fonts and control sizes are.
> 
> No, sizers are a tiny part of a much bigger problem. Sizers might be the
> key to solve parts of the "look" problem, they don't address any of the
> "feel" problem.

Admittedly, to some extent there is a lowest common denominator problem
inherent in any UI toolkit that tries to be crossplatform and use the
platform's native GUI. But for the most part, that just isn't the case
anymore in a practical sense.

Why not use the best crossplatform native toolkit (wxPython) and then if
you need native features that aren't provided, use ctypes or something
to get access to the native GUI? Nothing in wxPython or Dabo prevents
you from doing that.


> But you clearly have a point here, so let me rephrase: "Crossplatform
> toolkits/frameworks suck. All of them. No exception. UNLESS you only
> target the lowest common denominator, aka Windows and its Linux
> followers".

Absolutism sucks. Please try not to be so black and white about things,
and you may find you enjoy life more.


> Now, the OP *explicitely* said that "[his] requirement is that the
> application needs to look as good on Windows as on the Apple Mac", so
> the rephrasing does not apply in this case. So here's a last try:
> 
> "Crossplatform toolkits/frameworks suck. All of them. No exception.
> ESPECIALLY if one of your target is Mac OS".

It is much more nuanced than that.


-- 
pkm ~ http://paulmcnett.com


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


Re: DOS, UNIX and tabs

2006-12-29 Thread Paul McNett
Steven D'Aprano wrote:
> But I think we all agree that mixing tabs and spaces is A Very Bad Thing.

I like mixing tabs and spaces, actually. Tabs for indentation, and 
additional spaces to make the code "look pretty". Somebody please tell 
me why this is bad and I'll stop.

class Apple(object):
def contrived_example_function(self, argument1, argument2,
   argument3, argument4):
print "hello, world"

Apparently, emacs in python mode follows this convention, too. I like it 
because I get the best of both worlds: the only thing against using 
tabs-only-indentation is that wrapping long lines can be quite ugly, 
while space-only-indentation allows for beautifying it somewhat by 
lining up the columns to match. Tabs+spaces allows the "lining up" with 
spaces to be explicitly separate from indentation.

-- 
pkm ~ http://paulmcnett.com

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


Re: DOS, UNIX and tabs

2006-12-30 Thread Paul McNett
Sebastian 'lunar' Wiesner wrote:
> Paul McNett <[EMAIL PROTECTED]> typed
> 
>> Steven D'Aprano wrote:
>>> But I think we all agree that mixing tabs and spaces is A Very Bad
>>> Thing.
>> I like mixing tabs and spaces, actually. Tabs for indentation, and
>> additional spaces to make the code "look pretty". Somebody please tell
>> me why this is bad and I'll stop.
>>
>> class Apple(object):
>> def contrived_example_function(self, argument1, argument2,
>> argument3, argument4):
>> print "hello, world"
>>
>> Apparently, emacs in python mode follows this convention, too.
> 
> That doesn't seem like a standard settings to me. I can't remember
> changing the indentation settings for python, nonetheless my gnu emacs
> uses four spaces for indentation. Placing wrapped lines into ordered
> columns is done by inserting additional spaces. This all happens
> automatically; you never need to insert spaces manually...

I never tried emacs, but somebody once told me that if you have set
indentation-by-tab, it will indent with tabs but insert additional
spaces in wrapped lines to look pretty.


>> I like it because I get the best of both worlds: the only thing
>> against using tabs-only-indentation is that wrapping long lines can be
>> quite ugly, while space-only-indentation allows for beautifying it
>> somewhat by lining up the columns to match.
> 
> Did you try to open your code files with another editor, which has a
> different length for tabulator chars? It would look quite ugly, I
> guess...

Actually, no. Everyone can choose their own number of spaces-per-tab and
it'll look right, as long as everyone uses a monospace font.

-- 
pkm ~ http://paulmcnett.com


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


Re: Visual Report Editor

2006-02-16 Thread Paul McNett
Pawel wrote:
> I plan to make Visual Reporting Editior, a new product for
> corporate-class systems. Data will be in XML and in my application,
> designer should be able to make fascinating templates of reports. I
> will use Python and MSVS 2005 Pro. My question is, which libaries will
> be useful in my job. I plan to buy Qt and make visual layer of
> application using Qt. I'm making businessplan soI have to decide which
> tool will be useful. Is Qt best choice, maybe I should buy something
> different?

Before you go to all that work, please take a look at the Dabo Report 
Designer, which uses wxPython for the UI and ReportLab for the PDF 
generation.

There's a 23-minute screencast here which may give you an idea if its 
design is compatible with yours:

http://dabodev.com/documentation

It isn't complete and I could certainly use help making it so.

-- 
Paul


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


Re: commenting out blocks of code

2006-02-17 Thread Paul McNett
john peter wrote:
>  in java, i can  prevent a block of code from executing
> by bracketing the block with comment indicators, as shown
> below:
> /*
>   statement1 will not execute;
>   statement2 will not execute;
> */
>   statement3 will execute
> 
> is there a similar mechanism in python, other than prefixing
> the '#' character to the start of each statement i do  not
> want to execute (which gets old very quickly if one needs to
> comment and uncomment several statements a couple of
> times while "playing around with code" say during initial design)?

IMO this is a missing feature in Python. However, if the block of code 
you are wanting to comment out doesn't happen to contain any 
triple-quotes, you can surround the code with those. For example:

def myFunc(arg):
return arg + 2

"""
def myFunc(arg):
return arg + 1
"""

 >>> print myFunc(2)
4


-- 
Paul


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


Re: how do you move to a new line in your text editor?

2006-03-02 Thread Paul McNett
John Salerno wrote:
> But I read in the PEP that spaces are recommended over tabs. If this is 

If you like tabs, stick with tabs. There isn't any reason to use spaces 
unless your boss is demanding it. Tabs are the slightly better choice, 
in my humble opinion.

That said, you should be able to tell your editor how to behave in the 
indent/unindent case, no matter whether you use tabs or spaces. If not, 
time to switch editors! ;)

-- 
Paul


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


Re: Solipsis: Python-powered Metaverse

2005-05-10 Thread Paul McNett
Joseph Garvin wrote:
> I was looking at this earlier today because I was curious how they were
> going to handle performance concerns (both due to Python and bandwidth).
> I'm having trouble understanding all of the details -- what is the
> significance of the use of a torus for the world space? Does this
> somehow help in the computation of the convex hull?

I'm having trouble understanding how they are going to make this work
server-less, pure peer-to-peer. I just tried it out and it was cool: I
could move around in the world, get near other avatars and say "hey".
Only, I couldn't hear what they said back to me because I don't have UDP
port 6000 open on my firewall and forwarding to my laptop (and don't
want to do that either).

It is a shame: peer to peer has the potential to enable really cool,
imaginative multiuser worlds, but how many people are connecting
directly to the internet these days?

-- 
pkm ~ http://paulmcnett.com


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


Re: Solipsis: Python-powered Metaverse

2005-05-11 Thread Paul McNett
Ville Vainio wrote:
>>>>>>"Paul" == Paul McNett <[EMAIL PROTECTED]> writes:
> 
> 
> Paul> Only, I couldn't hear what they said back to me because I
> Paul> don't have UDP port 6000 open on my firewall and forwarding
> Paul> to my laptop (and don't want to do that either).
> 
> Paul> It is a shame: peer to peer has the potential to enable
> Paul> really cool, imaginative multiuser worlds, but how many
> Paul> people are connecting directly to the internet these days?
> 
> FWIW, In Finland all home *DSL and Cable internet connections (that I
> know of) are connected "directly" to the internet (in the sense that
> all ports are open). Blocking is reserved for the modem, just the way
> it should be...

Sure, that's how it is here in the US too. You have a modem/router
supplied by the cable or DSL company that provides DHCP and NAT for
outbound traffic. The fact that the internal computers have private
addresses (eg 192.168.1.5) keeps them from being accessed directly from
the outside. The modem still gets access to all ports[1], and most have
ways to set up simple "port forwarding" to, say, listen for UDP traffic
on port 6000 and forward it on to 192.168.1.20.

The problem is, that last step required setup by the user of one of the 
computers in the LAN. Sure, this is a home so there is likely only one 
or two computers in the LAN, but it is still a painful thing to ask 
normal users to configure their firewall, and what if both computers 
wanted to participate on the port 6000 fun?

[1] Although, some ISP's are taking it upon themselves to drop or reject 
port 25 traffic. A wrong but understandable stopgap solution to the 
problem of peoples toy machines getting infected by malware - at least 
those machines won't be able to send mailbombs anywhere else.

-- 
pkm ~ http://paulmcnett.com


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


Re: Solipsis: Python-powered Metaverse

2005-05-11 Thread Paul McNett
Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Paul McNett  <[EMAIL PROTECTED]> wrote:
> 
>>[1] Although, some ISP's are taking it upon themselves to drop or reject 
>>port 25 traffic. A wrong but understandable stopgap solution to the 
>>problem of peoples toy machines getting infected by malware - at least 
>>those machines won't be able to send mailbombs anywhere else.
> 
> 
> I've heard of other kinds of port-blocking, too, making it difficult or
> impossible to set up VPNs, for example.

See, they *are* out there, trying to take away my freedom! :) The 
logical extension of this is that cable/dsl providers will only allow 
destinations of port 80 and 25, because those two services are what "the 
Internet" is to 80% of the ISP's customers. Actually, you can scratch 
port 25 because more and more people are using webmail (ick!), but you 
probably need to add 443. So "what the Internet is" becomes set in stone 
instead of what it naturally wants to do: evolve.

-- 
pkm ~ http://paulmcnett.com

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


Re: Faster GUI text control

2005-05-13 Thread Paul McNett
Jeremy Bowers wrote:
> The problem is that if you're really looking for performance, it may
> differ based on the characteristics of the text and the quality of the
> target computer, the platform (which you don't mention; GTK may scream in
> Linux and make you scream in Windows...), etc., and there may be no one
> person who can give you a firm "This is the best solution for your
> situation" answer.

Also, it must be said that thousands of lines of text in a GUI control 
may not be necessary. Do the users really need to be able to scroll 
through that much text all at once in the general case, or do they 
perhaps only ever need to see the last few dozen lines? Could they 
instead "page" through the text in swallowable morsels, say a couple 
hundred lines at a time?

Python can handle gargantuan amounts of text with little noticable 
performance penalty, while GUI controls aren't necessarily designed for 
that. What I'm getting at is that you could still have the entire string 
in memory, but only feed portions of that string to the GUI text control 
at a time.

I'm jumping in here - perhaps the OP already told us what the 
application is, but I'm curious why it is necessary to have thousands of 
lines displayed and editable all at once, and wonder if the design 
should be reconsidered. I know that native Windows controls in 
particular tend to get really squirrly and unpredictable once you push 
into thousands of lines.

-- 
pkm ~ http://paulmcnett.com

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


Re: Solipsis: Python-powered Metaverse

2005-05-13 Thread Paul McNett
Terry Reedy wrote:
> While the above is not directly on-topic for c.l.p, it does suggest 
> possible design considerations for users of the socket module and packets 
> built on top ;-).
> -- including Solipsis, which is such.

I contributed to the thread going kind of off-topic, so I'll just follow 
up by saying that the Solipsis Metaverse could have the potential to be 
the killer app that gets Python noticed in a widespread, mainstream 
fashion (with no value judgement attached to that - I'm not sure that 
development would be particularly good or bad for Python). The ability 
for anyone to design their own entities and then put them into a common 
metaverse, where they exist in "concrete" fashion just by virtue of 
being there at a given position and size, and that none of the entities 
in the metaverse are managed by a central server, is just amazingly 
cool. The coolness factor could be like that of the web in 1993, with 
Python enabling all kinds of normal people to learn programming so they 
can make their mark with their avatar in the virtual world - indeed more 
and more of daily life may become dependent on dealing with people in 
the metaverse instead of face-to-face. And once the masses learn how to 
really wield the power of their computers, watch out the human race just 
evolved a little more.

But the ability for maliciousness to be unleashed is an unfortunate 
side-effect too, and the Python community should be prepared for the 
language becoming the scapegoat, but then again each entity in the 
metaverse is really its own server, and can limit its input/output just 
like we do now with Python web apps.

Um, when I started this message I meant to bring it back on topic. Oh, 
well. Hiro forgives me, I am sure.

-- 
pkm ~ http://paulmcnett.com

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


Re: Python forum

2005-05-17 Thread Paul McNett
Rocco Moretti wrote:
> Dave Brueck wrote:
> 
>>Grant Edwards wrote:
>>
>>>[In case you can't tell, I hate web forums.  I've never seen a
>>>single one with a suable UI.]
>>
>>Amen! Generally they are an abomination.
> 
> It may seem snobish, but my main gripe with most of the web-forums I've 
> seen is the people using them. There are far too many content-free "Me 
> too" posts, which are horribly difficult to filter out (due to the poor 
> UI). It's partly the web-forum's fault - the really bad ones have posts 
> with some cute/animated smiley as the sole content. It's rare that 
> usenet has such posts, because a colon and a right paren in text doesn't 
> seem nearly as interesting as some saccarine singing, dancing, yellow blob.

I think that web forums are great in one case: supporting nontechnical 
end users on the use and configuration of your product, in a 
free/community-based support arrangement. The forum needs a moderator to 
trim and condense as appropriate, and the help desk needs to monitor the 
forum and interface with the developers as necessary.

The benefits versus newsgroup/listserv in this case basically boil down to:
+ users already know how to use their web browser, but -let's be honest- 
it's a stretch to get them to subscribe to a list - you'd have to hold 
their hand through every step of the setup making it less costly to just 
offer free phone support for their issue.

But that's it. Otherwise, web forums just waste everyone's time.

So for a language like Python, where you presuppose that most people 
using the product are technically savvy enough to operate a newsreader 
or mail client, a web forum approach just isn't going to gain much 
popularity. Web forums for people that know how to use their computers 
are just a horrible waste of time, but perhaps more importantly people 
no longer have control over their environment and are forced to navigate 
a particular UI instead of being able to put together their own 
preferred approach.

-- 
pkm ~ http://paulmcnett.com

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


Re: execution error

2005-05-23 Thread Paul McNett
Ximo wrote:
> Hello, I'm programing an advanced calculator, and I have many problems with 
> the execution errors, specually with the division by 0.
> 
> And my question is how can show the execution error whitout exit of the 
> program, showing it in the error output as


Wrap the math in a try/except block such as:

# Handle the zero-division plus maybe some others:
exceptions_to_handle = (ZeroDivisionError,)

try:
# do the math here
result = eval(my_math)
except exceptions_to_handle, e:
# gracefully handle here
result = str(e)
# show the result in the calculator here
print result

... or something like that. The point is you need to handle the zero 
division error while not handling other, unexpected error conditions.



-- 
pkm ~ http://paulmcnett.com

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


Re: Python Impact Analysis Tool ?

2005-05-25 Thread Paul McNett
Terry Hancock wrote:
> On Wednesday 25 May 2005 08:27 am, [EMAIL PROTECTED] wrote:
> 
>>Is there an impact analysis tool out there that can cross reference
>>python -- VB has a couple of these tools (eg. Visual Expert)
> 
> I could be wrong, but my first impression is that that must be
> VB jargon for something we might know under another name.

Yep, I think we know it as 'unit testing'.

 From the Visual Expert site (http://visual-expert.com), impact analysis 
refers to taking a given variable or function name, and finding 
everywhere in the project where that name is referenced, for the purpose 
of determining what bad things will happen when that variable or 
function is changed somehow. The tool won't tell you what bad things 
will happen, just list other code segments that depend on the name in 
question.

While such a tool may indeed be helpful in quickly understanding a 
project, and there may indeed be such a tool for Python, I think that 
most Pythonistas would find unit testing has a better impact on 
developer productivity, for the common case of wanting to make a change 
and also fix any dependent structures: just do it and then discover/fix 
any repercussions!


-- 
pkm ~ http://paulmcnett.com

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


Re: __init__() not called automatically

2005-05-25 Thread Paul McNett
Sriek wrote:
> hi,
> i come from a c++ background. i ws happy to find myself on quite
> familiar grounds with Python. But, what surprised me was the fact that
> the __init__(), which is said to be the equivlent of the constructor in
> c++, is not automatically called. 

What do you mean by automatically? :

Python 2.4.1 (#2, May  5 2005, 09:45:41)
[GCC 4.0.0 20050413 (prerelease) (Debian 4.0-0pre11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> class A(object):
... def __init__(self):
... print "in __init__"
...
 >>> a = A()
in __init__

So __init__ is definitely called upon instantiation.  It is true that if 
you derive from A and override __init__, A.__init__ won't be called 
unless done so explicitly like:

class B(A):
def __init__(self):
print "in B.__init__()"
super(B, self).__init__()

> I'm sure there must be ample reason
> for this. I would like to know why this is so? This is my view is more
> burden on the programmer.

It isn't that much practical burden, and IMO it makes perfect sense. 
When you override a method of a class, you want to have to explicitly 
call superclass code, not have it run automatically, else you lose 
control of the flow.


> Similarly, why do we have to explicitly use the 'self' keyword
> everytime?

This is closer to a wart, IMO, but once you've used Python for a while 
you'll come to understand why this is so. Basically, everything in 
Python is either a namespace or a name in a namespace. In the case of 
the self reference which Python sends as the first arg automatically, 
the method needs to bind that to a local name which is, by convention 
only, 'self'.


> Every kind of help would be welcome.

You've found the right place to hang out. Welcome!


-- 
pkm ~ http://paulmcnett.com

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


Re: Case Sensitive, Multiline Comments

2005-05-26 Thread Paul McNett
Mike Meyer wrote:
> "Elliot Temple" <[EMAIL PROTECTED]> writes:
>> Also, why aren't there
>>multiline comments?  Would adding them cause a problem of some sort?
> 
> Because no one every really asked for them. After all, there are two
> formats for multi-line strings, which the interpreter will build and
> then discard. There are tools that recognize multi-line strings after
> function/method definitions and treat them as function documentation.
> 
> Adding multiline comments probably wouldn't be a problem - you'd just
> have to come up with an introductory character sequence that can't
> occur in the language (not that that stopped C). But you'd have to get
> someone to write the code, then someone with commit privs to decide it
> was useful enough to commit. That seems to be a lot of work for very
> little gain.

Don't we already have multi-line comments in the form of string literals?

-- 
Paul McNett
http://paulmcnett.com

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


Python/Excel AddIn (was:Re: Does Python have a Template::Extract equivalent from Perl's CPAN)

2005-05-27 Thread Paul McNett
Please start a new thread when appropriate.

combinational.logic $ soc-ip.com wrote:
> Can you please elaborate on how to use Python for MS Excel AddIn
> development? Is this easy to do?  I would love to be able to create
> custom extensions to Excel using python!  IMHO Python is much better
> than Perl due to its OOP features.

Do you mean automating Excel sheets using Python? If so, you need to get 
a COM interface from Python (see Mark Hammond's win32all Python 
extensions for this), and you need to figure out the proper com calls, 
which is easiest by going into Excel and recording a macro, and then 
taking a look at the vbscript the macro recorded.

-- 
Paul McNett
http://paulmcnett.com

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


Re: Beginner question: Python types

2005-05-31 Thread Paul McNett
Uppal, Deepali wrote:
> Hello,
Hello, and welcome to the world of Python. Don't take anything we say 
too personally, it is meant to help.

> I am facing a bit of a problem due to python implicitly 
> attaching a type to an object. 

Ooh. In general, don't say 'implicit'. For the most part, Python only 
does things explicitly. See the Zen of Python by opening a Python 
interpreter and typing "import this".


> I will briefly tell you the problem that
> I am facing. I am trying to print the docstring of a test case in 
> my pyUnit base test class. I accept the name of the test class as
> a command line option. So instead of printing the docstring of
> the test case, it prints the docString of a string object.

Which is expected, because all command line options are strings. I 
assume you are getting the command line option using the idiom:

import sys
options = sys.argv[1:]

> I would like to give an example here
> import test_script  
> 
> gettatr( test_script.test_class.test_case, ‘__doc__’)

I think you meant:

print getattr(test_script.test_class.test_case, '__doc__')


> With this simple code, I am able to print the docstring
> of the test case.

Yep, Python is simple and expressive.


> However, since I accept the test case information as a command line
> option. So instead of printing the docstring of the test case it
> prints the docstring of a string object.

Right, because all command line options are strings, since that is all 
the shell can really hand off to Python.


> Is there someway, I can tell the script to change the type of
> the object from string to an instancetype of a test case?

In your first example, you import the test_script, and then do a 
getattr() on the test_class inside test_script.py. If you are trying to 
mimic that, and sending one or more test_script's, your code would look 
something like:

import sys

for test_module in sys.argv[1:]
try:
_module = __import__(test_module)
_class = _module.test_class
_case = _class.test_case
print _case.__doc__
except ImportError:
print "Couldn't import module '%s'. Skipping..." % test_module  


> I am quite a newbie in python so I would appreciate any help on this.

The above should get you started, even though it won't satisfy your 
exact needs.

-- 
Paul McNett
http://paulmcnett.com

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


PYSH? (was:Re: calling ksh script from python)

2005-06-02 Thread Paul McNett
Cameron Laird wrote:
> Infidel.  While I sure feel that way about csh(1), it
> surprises me you'd criticize ksh(1) so.  'Fact, 'mong
> all the *sh-s, I *recommend* ksh for programming.  May-
> be the two of us see things differently.

I keep wondering how difficult it would be to make a Python shell that 
exposes all of Python but also includes some builtin commands such as 
cd, mkdir, etc., that are just names bound to os.chdir, os.mkdir..., and 
is smart enough to take a given command from the user and try to do a 
os.system() on it based on the path. IOW, I'd love to have all of Python 
available as my unix shell, while still doing shell-type stuff such as 
traversing directories, launching applications, etc.

There's likely a project that does this already that I'm just unaware of.

-- 
Paul McNett
http://paulmcnett.com

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


Re: Start application & continue after app exits

2005-06-09 Thread Paul McNett
Guy Lateur wrote:
> I was wondering if it would be possible to launch an application, block 
> until the app exits, and do some cleanup afterwards.

> Maybe an example will be clearer: I would like to make a temperary (text) 
> file, open it with MS Word for the user to edit/layout/print, and then 
> delete the temp file after the user shuts down Word. Is this feasible?

Something like:

import os
import tempfile

testString = "Life is but a dream."
fileName = tempfile.mktemp()
print fileName
open(fileName, "w").write(testString)
os.system("gedit %s" % fileName)
os.remove(fileName)

---
Note that I'm on Linux, and instead of launching Word I'm launching an 
editor named "gedit". You could likely change that call to winword.exe, 
but I haven't tested it on Windows.

Also note that this method of creating tempfiles is technically unsafe, 
as it is theoretically possible that another process would create a file 
of the same name in the same directory and then try to use it, resulting 
in a race condition between the two processes. This is practically 
unlikely, however, and I'm a pragmatist.


-- 
Paul McNett
http://paulmcnett.com

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


Re: Any way to not create .pyc files?

2005-06-09 Thread Paul McNett
Lonnie Princehouse wrote:
> Is there any way to run Python WITHOUT trying to create .pyc files (or
> .pyo) or to have Python not attempt to import the .pyc files it finds?

You could roll your package into a zip archive and then import that. For 
instance, keep your main.py out of the archive and put everything else 
in. Then, at the top of main.py:

import sys
sys.path.insert("network_path/package.zip")

import package
# do normal stuff with package here.

As long as you zipped up the package will all .pyc and .pyo files 
removed, Python will have no choice but to compile the files every time 
they are imported - unless I'm grossly mistaken Python won't put the pyc 
files into the zip archive, or modify any that were there already.

As far as the maintenance headache of distributing updated copies to 
individual workstations, IMO this just requires a little forethought and 
then it isn't a headache at all. Instead of the users starting the 
application directly, they could start a starter application that checks 
with the server to determine if local files need to be updated, and if 
so grab them and then start the main app. This actually removes 
headaches in the Windows world, where you can't drop-in updates to 
programs that are currently running.

What I've done in the past adds on to the starter application idea, and 
has the main application check to see if there are updates to the 
starter application, and if so pull those changes down upon exit of the 
main application. I just saved the file locations locally in an INI file.

-- 
Paul McNett
http://paulmcnett.com

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


Re: Start application & continue after app exits

2005-06-09 Thread Paul McNett
Mike Meyer wrote:
> "guy lateur" <[EMAIL PROTECTED]> writes:
> 
> 
>>>>Also note that this method of creating tempfiles is technically unsafe,
>>>>as it is theoretically possible that another process would create a file
>>>>of the same name in the same directory and then try to use it, resulting
>>>>in a race condition between the two processes. This is practically
>>>>unlikely, however, and I'm a pragmatist.
>>
>>I see what you mean, but wouldn't a call to open(fn, 'w') on a filename 
>>that's in use (for reading or writing) result in an error condition or 
>>something? I'm a noob, btw.
> 
> 
> Not necessarily - it depends on the OS. Unix is quite happy to let
> multiple processes read/write a file at the same time.
> 
> FWIW, this also means that the methodology as outlined is
> insecure. Some other program can read the temporary file as it exists
> on the disk, thus disclosing it's contents to unauthorized readers.

Right. So we are all adults here and if that matters to your application 
you've got to find a different way, perhaps by using

tmpFile = tempfile.NamedTemporaryFile()

instead of

tmpFile = tempfile.mktemp()

and

os.spawnlp(os.P_WAIT, "winword.exe", "winword.exe", tmpFile.name)

instead of

os.system("winword.exe %s" % tmpFile)

but I don't think all (if any) versions of Windows can handle opening 
that file while we are holding it open already. And I guess it still 
doesn't make it secure because the file exists on disk and can be read.

So I stand by my prior, simpler solution, that will work portably and 
reliably for all practical purposes, purposeful maliciousness excepted. 
If you are worried about security, you would't be saving the file to the 
temp directory in plain text anyway.

If there is a portable, reliable, secure, and simple solution that I've 
overlooked, however, I'm all ears. :)

Now, if the OP's requirement is specifically for winword on Windows, a 
more specific approach could be used that doesn't involve saving any 
temporary files at all, such as by using COM automation to build the 
document. But I hate nonportable solutions! :)

-- 
Paul McNett
http://paulmcnett.com

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


Re: Single Application Instance Example

2005-06-14 Thread Paul McNett
Chris Lambacher wrote:
> Does anyone know of an example of how to make a Python program only
> run a single instance.  I am specifically looking for examples for
> win32.

The Python Cookbook, Second Edition, page 380, recipe 9.9: Determining 
Whether Another Instance of a Script is Already Running in Windows, 
suggests using a mutex kernel object to be safe from race conditions:

from win32event import CreateMutex
from win32api import GetLastError
from winerror import ERROR_ALREADY_EXISTS
from sys import exit
handle = CreateMutex(None, 1, 'A unique mutex name')
if GetLastError() == ERROR_ALREADY_EXISTS:
print "I exist already"
exit(1)
else:
print "I don't exist already"


> I think I should be able to do this with win32all but the method is
> not obvious.  Preferably I would like to be able to get a handle to
> the already running instance so that I can push it to the foreground
> as well.

There are ways using win32 to get the handle to the existing process, 
but I'm too rusty with win32 to offer that part of the solution.


-- 
Paul McNett
http://paulmcnett.com

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


Re: splitting delimited strings

2005-06-15 Thread Paul McNett
Mark Harrison wrote:
> What is the best way to process a text file of delimited strings?
> I've got a file where strings are quoted with at-signs, @like [EMAIL 
> PROTECTED]
> At-signs in the string are represented as doubled @@.

Have you taken a look at the csv module yet? No guarantees, but it may 
just work. You'd have to set delimiter to ' ' and quotechar to '@'. You 
may need to manually handle the double-@ thing, but why don't you see 
how close you can get with csv?

> @rv@ 2 @db.locks@ @//depot/hello.txt@ @mh@ @mh@ 1 1 44
> @pv@ 0 @db.changex@ 44 44 @mh@ @mh@ 1118875308 0 @ :@@: :: @
> 
> (this is from a perforce journal file, btw)


-- 
Paul McNett
http://paulmcnett.com

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


Re: Build EXE on Mac OsX 10.4

2007-06-13 Thread Paul McNett
Tempo wrote:
> Has anyone sucesfully built a *.exe file on a mac operating system
> before from a *.py file? I have been trying to do this with
> pyinstaller, but I keep getting errors and I don't know how to install
> UPX properly. I tried putting the linux UPX folder in my python 2.4
> directory, but that didn't work. I am just generally confused right
> now. Ha. If anybody can lend me some insight I would really appreciate
> it. Thank you for taking the time to read this post.

You need to build Mac Apps on Mac, Windows EXE's on Windows, and Linux 
ELF's on Linux. You can't build a windows.exe from Mac, just as you 
can't build a mac.app from Windows.

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Build EXE on Mac OsX 10.4

2007-06-14 Thread Paul McNett
Sherm Pendley wrote:
> "Gabriel Genellina" <[EMAIL PROTECTED]> writes:
> 
>> En Wed, 13 Jun 2007 17:35:19 -0300, Paul McNett <[EMAIL PROTECTED]> escribió:
>>
>>> Tempo wrote:
>>>> Has anyone sucesfully built a *.exe file on a mac operating system
>>>> before from a *.py file? I have been trying to do this with
>>>> pyinstaller, but I keep getting errors and I don't know how to
>>>> install  [...]
>>> You need to build Mac Apps on Mac, Windows EXE's on Windows, and Linux
>>> ELF's on Linux. You can't build a windows.exe from Mac, just as you
>>> can't build a mac.app from Windows.
>> That's not entirely true. gcc on linux can generate a Windows EXE, and
>> using: python setup.py bdist_wininst, you can generate a complete
>> binary  installer for Windows. I'm not sure if this can be done on a
>> Mac too.
> 
> In principle, certainly - there's even a MacPort package for a complete
> cygwin installation. I've built a number of packages with it - SDL and
> several related libraries, for instance. There are also ELF cross-compiler
> MacPort packages, presumably for building Linux binaries.
> 
> On the other hand, I *haven't* tried any of those compilers with setup.py,
> and I have no idea if it can support those targets in practice. :-(

There's the rub. In practice, it is hard enough getting my setup.py 
correct for building a nice windows.exe from Windows. Plus, the first 
thing I want to do after building an exe is *test* it on the target 
platform...

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: OS X install confusion

2007-06-14 Thread Paul McNett
John Fisher wrote:
> Ted <[EMAIL PROTECTED]> wrote:
> 
>> On Jun 14, 1:31 pm, Kevin Walzer <[EMAIL PROTECTED]> wrote:
>>> John Fisher wrote:
 Hi Groupies,
 I have an Intel Macbook running OS X 10.4.
 It came installed with Python 2.3.5. I have since installed MacPython
 with version 2.4.4, cool.
 When I open a bash terminal session and type python, it brings up
 version 2.3.5. If I type IDLE it brings up version 2.4.4.
 My question: what do I have to do to get it to bring up 2.4.4 with the
 "python" command?
 Thanks for bringing light to my ignorance.
 JF
>>> Sounds like a path problem. Apple's system Python is installed in
>>> /usr/bin. Your installation is probably in /usr/local/bin. Edit your
>>> profile or use the full path.
>>>
>>> --
>>> Kevin Walzer
>>> Code by Kevinhttp://www.codebykevin.com
>> The default python on tiger (2.3.5) is sym-linked to /usr/bin/python
>> and /usr/bin/pythonw.
>>
>> I found it easier to relink to the new installation path. This also
>> leaves /usr/bin/python23 and /usr/bin/pythonw23 still linked to the
>> original version if you want to quickly check something.
>>
>> Cheers,
>> Ted
> 
> OK, please give a little more information how I can accomplish this
> "re-link".

Your Python 2.5 is likely installed here:

/Library/Frameworks/Python.framework/Versions/Current/bin

But OS X comes with a "system Python", version 2.3.5, likely installed here:

/usr/bin

If you look at /usr/bin, you'll see:

lrwxr-xr-x   1 root  wheel  9 Jan 31 17:24 python -> python2.3
lrwxr-xr-x   1 root  wheel 72 Jan 31 17:24 python2.3 -> 
../../System/Library/Frameworks/Python.framework/Versions/2.3/bin/python
lrwxr-xr-x   1 root  wheel 10 Jan 31 17:24 pythonw -> pythonw2.3
-rwxr-xr-x   1 root  wheel  29704 Aug 19  2006 pythonw2.3

So, python is linked to python2.3, and python2.3 is in turn linked to 
/System/Library/Frameworks/Python.framework/Versions/2.3/bin/python

You need to (warning: watch for line wrap):

sudo -s

cd /usr/bin
ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/python 
python_current
ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/pythonw 
pythonw_current
rm python
rm pythonw
ln -s python python_current
ln -s pythonw pythonw_current

However, that isn't what I did. I like the system being able to find and 
use the system-installed python, but I like my scripts to use the python 
version I installed (2.5). To get that, skip the above symlinking and 
instead edit your .bash_profile file (hidden file inside your home 
directory) and put these lines at the top:

PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}
export PATH

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New guy help with setup

2007-07-12 Thread Paul McNett
meg99 wrote:
> I just downloaded 2.5 and read the readme file.  It says "Before you
> can build Python, you must first confiigure itStart by running the
> script "./configure".
> 
> I can't find "./configure"
> 
> I am running Windows XP SP2

You downloaded the wrong file. You want the Windows Installer:
http://python.org/ftp/python/2.5.1/python-2.5.1.msi

HTH
Paul

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New guy help with setup

2007-07-12 Thread Paul McNett
meg99 wrote:
> On Jul 12, 4:24 pm, Paul McNett <[EMAIL PROTECTED]> wrote:
>> meg99 wrote:
>>> I just downloaded 2.5 and read the readme file.  It says "Before you
>>> can build Python, you must first confiigure itStart by running the
>>> script "./configure".
>>> I can't find "./configure"
>>> I am running Windows XP SP2
>> You downloaded the wrong file. You want the Windows 
>> Installer:http://python.org/ftp/python/2.5.1/python-2.5.1.msi
> My applogies - I did download and install 2.5.1

In that case, open up your command window (Start|Run "cmd" ).

Type 'python' at the c:\ prompt.

Or, Start|All Programs|Python 2.5|IDLE

Enjoy!


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New guy help with setup

2007-07-12 Thread Paul McNett
meg99 wrote:
> On Jul 12, 4:35 pm, Paul McNett <[EMAIL PROTECTED]> wrote:
>> meg99 wrote:
>>> On Jul 12, 4:24 pm, Paul McNett <[EMAIL PROTECTED]> wrote:
>>>> meg99 wrote:
>>>>> I just downloaded 2.5 and read the readme file.  It says "Before you
>>>>> can build Python, you must first confiigure itStart by running the
>>>>> script "./configure".
>>>>> I can't find "./configure"
>>>>> I am running Windows XP SP2
>>>> You downloaded the wrong file. You want the Windows 
>>>> Installer:http://python.org/ftp/python/2.5.1/python-2.5.1.msi
>>> My applogies - I did download and install 2.5.1
>> In that case, open up your command window (Start|Run "cmd" ).
>>
>> Type 'python' at the c:\ prompt.
>>
>> Or, Start|All Programs|Python 2.5|IDLE

> I opened the command window and typed 'python'
> got 'not recognized as a command'

Add c:\python25 to your Windows system path.

> went to the python25 folder and typed 'python'
> got the >>> prompt

Good! Python is installed and working normally.

> typed './configure'
> got 'no Python documentation found for './configure'

You don't need to ./configure. That's for when you are going to compile 
Python from source code into a binary, which you don't need to do 
because you installed a precompiled binary for Windows.


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice on sending images to clients over network

2007-07-22 Thread Paul McNett
Frank Millman wrote:
> I guess the point of all this rambling is that my thought process is
> leading me towards my third option, but this would be a bit of work to
> set up, so I would appreciate any comments from anyone who has been
> down this road before - do I make sense, or are there better ways to
> handle this?
> 
> Any suggestions will be much appreciated.

I would put the images into a static web directory, either on the same 
or different server. Then your main server just sends the url (or 
relevant portion of the url, or list of all urls to download), and then 
the client grabs the images from your image server using urllib.

Let Apache do what it's good at, instead of reinventing that particular 
wheel.

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and GUI

2007-05-21 Thread Paul McNett
[EMAIL PROTECTED] wrote:
> Just wondering on what peoples opinions are of the GUIs avaiable for
> Python?

Python has, I believe, 4 compelling choices for GUI library: Tkinter, 
wxPython, PyQt, and PyGTK. Like everything in life, each has their 
relative merits and downsides. Briefly, here are my feelings on each, 
but I'm mostly versed in wxPython.


Tkinter:

Pros: comes with Python out of the box; terse; easy

Cons: owner-drawn (not-native OS widgets); limited in out-of box 
functionality; kind of ugly


wxPython:

Pros: easy to install binary on all platforms, active development, 
active friendly community of contributors, native os base widgets on all 
platforms.

Cons: hard to build from source on all platforms, everything but the 
kitchen sink comes with it, and some things are pretty buggy still or 
abandoned.

PyQt:

Pros: looks good on all platforms, easy to install and use.
Cons: licensing issues require you to understand lots of specifics; 
owner-drawn widgets.

PyGTK:

Can't comment because I haven't used it. The major con in my mind is 
that (I think) you need the Gtk library to be installed on all 
platforms, so on OS X / Windows the widgets won't look platform-native.


> All I am doing is prompting users for some data (listbox, radio
> buttons, text box, ect...).  Then I will have some text output, maybe
> a scrolling text message as things are happening.

I think each of the GUI libraries would be able to handle this easily.


> I have some minor things I need to do, for example, if Checkbutton X
> is clicked, I need to disable TextBox Y, and I would like to display
> the scrolling text (output)

Again, this is simply responding to events as they happen. You set up a 
callback function with your reactive code, and tell the GUI library to 
call that function when the event occurs.


> Ultimately, is it worth downloading and learning some of the packages
> avaiable for Python, or should I just stick to the Tkinter stuff that
> is included.

I think everyone should use wxPython, but I'm biased.


> More specifically, has anyone used the Qt stuff for python, easy to
> use?

I've used it and it is easy, yes. Relative ease I can't answer though, 
because I find wxPython extremely easy due to depth of use over the years.

Shameless plug: consider using Dabo on top of wxPython - we feel it 
makes wxPython even easier and more pythonic, but admittedly there's a 
bit of a learning curve there too. Even though Dabo is a full 
application framework originally meant for desktop database 
applications, it is modular and you can choose to only use the UI 
bits... http://dabodev.com

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dabo framework dependancies

2007-05-23 Thread Paul McNett
Peter Decker wrote:
> On 5/22/07, daniel gadenne <[EMAIL PROTECTED]> wrote:
> 
>> I'm considering moving over to dabo for wxpython development.
>> However I do not write traditional database applications
>> à la foxpro (I'm a 20 years user of fox...) anymore.
>> Only xml-fed applications.
>>
>> I'm a bit hesitant to jump onboard since dabo seemns to carry
>> over its own lot of database connectivity dependancy.
>>
>> Can you reasonably use dabo for plain datafree application?
> 
> That's exactly how I use it. I write apps that don't use database
> servers, and don't have any database programs installed. I just want
> the dabo.ui stuff, since it makes wxPython so easy to work with.

Dabo has three main modules: db, biz, and ui, and an overarching 
application object. Every class descends from an abstract dObject. For 
database apps, you'd typically set some connection information in the db 
layer, put all your business code in the biz layer, and define your GUI 
in the (you guessed it) ui layer. You can certainly do what Peter has 
done and only use the ui layer and application object. I've done this 
myself and if I ever had to code a non-database UI that's probably what 
I'd do, too. Although I have to admit I can't really picture an 
application that doesn't need to save data. Here's a simple example that 
puts up a textbox:

"""
import dabo
dabo.ui.loadUI("wx")

app = dabo.dApp()
app.setup()

frm = app.MainForm
tb = dabo.ui.dTextBox(frm, Value="Type in here", FontBold=True)

app.start()
"""

You can easily define your own subclasses, too:

"""
import dabo
dabo.ui.loadUI("wx")

class MyRadioList(dabo.ui.dRadioList):
   def initProperties(self):
 self.Choices = ["Snakes", "Bees", "Fishes"]

   def onHit(self, evt):
 print "Radio choice '%s' selected." % self.Value

app = dabo.dApp()
app.setup()
frm = app.MainForm
rl = MyRadioList(frm)
app.start()
"""

So, yes, you can reasonably use Dabo even if you have no traditional 
database in the mix.

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python script not mapping our site correctly?

2007-05-24 Thread Paul McNett
[EMAIL PROTECTED] wrote:
> We have been using the Google recommended python script for about a
> year. 

Which script would that be? Googling for 'python script' yields approx. 
27 million hits.

> We recently realized that the script was not crawling our sites
> url's, but just our folders which reside on the server. 

The behavior of the script recently changed, or you were running the 
script for a year not realizing what its purpose was?

> The python
> script seems to be designed for 'non database' sites, not a site which
> is using .asp, and has dynamic pages.

It sounds like your script is just traversing a directory structure on 
disk, presumably indexing the text in the files found there. I think it 
sounds like (but I'm guessing, here) that you want what is known as a 
web crawler, that communicates via http with your site, follows links, 
and indexes the resulting pages.

> We are an ecommerce site. What are other ecommerce sites using to
> create an xml file?

XML is mostly used to persist data of one sort or another. What kind of 
XML file do you want to create?

> Are they using the python script?

We aren't going to be able to help you with this question until you 
become *much more specific*:

+ Which python script? Where did you download it from and what is it called?

+ What is the purpose of the XML you want generated? (WAG: Submit to 
Froogle?)

+ What pages do you want indexed?

Usually, for database-driven ecommerce sites, for developing lists of 
products for submission to places like Froogle, I don't go via the web 
interface at all: I write python scripts (there's that word again!) to 
connect to the database, and run queries to determine the results, run 
that through a template for each line that figures out things such as 
the URL of the page that represents the product, etc.)

But I hesitate to say much more until we understand what you want your 
python script to do.


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get started as a xhtml python mysql freelancer ?

2007-05-25 Thread Paul McNett
gert wrote:
> I made something that i was hoping it could make people happy enough
> so i could make a living by providing support for commercial use of
> http://sourceforge.net/projects/dfo/
> 
> But in reality i am a lousy sales men and was wondering how you people
> sell stuff as a developer ?

In my experience, you don't make money by selling support unless you are 
a large company selling support for a large project or a wide array of 
projects. The people that will use your library will mostly be 
developers and not end-users, after all.

To make money from things you develop, I think you need to take your 
library and either build an application that has wide appeal and sell 
that, or sell yourself as a custom developer that can build the 
application the customer needs, using the tools you are comfortable 
with. You can then build in the cost of developing your library that you 
will reuse for the custom applications.

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updates in sqlite3 do not work

2007-05-29 Thread Paul McNett
Chris Fonnesbeck wrote:
> I have a script set up to perform UPDATE commands on an sqlite database 
> using the sqlite3 module. Everything appears to run fine (there are no 
> error messages), except that none of the UPDATE commands appear to have 
> actually updated the table. If I run each command on its own in a sqlite 
> session, the UPDATE command works fine, so it is not a SQL syntax issue. 
> UPDATE simply seems not to work. Any idea what the problem might be?

You need to explicitly commit the transaction e.g.:

import sqlite3.dbapi2 as sqlite

con = sqlite.connect("temp.db")
cur = con.cursor()

cur.execute("create table test (id INTEGER, name CHAR)")
cur.execute("insert into test values (1, 'bob')")
con.commit()

HTH
Paul

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice on sending images to clients over network

2007-07-22 Thread Paul McNett
Paul Rubin wrote:
> Frank Millman <[EMAIL PROTECTED]> writes:
>> Any suggestions will be much appreciated.
> 
> Why on earth don't you write the whole thing as a web app instead of
> a special protocol?  Then just use normal html tags to put images
> into the relevant pages.

I believe he has a full desktop client app, not a web app. Believe it or 
not, there's still a solid place for desktop applications even in this 
ever-increasing webified world.

Use the right tool for the job...


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice on sending images to clients over network

2007-07-22 Thread Paul McNett
Calvin Spealman wrote:
> On 7/22/07, Paul McNett <[EMAIL PROTECTED]> wrote:
>> Paul Rubin wrote:
>> > Frank Millman <[EMAIL PROTECTED]> writes:
>> >> Any suggestions will be much appreciated.
>> >
>> > Why on earth don't you write the whole thing as a web app instead of
>> > a special protocol?  Then just use normal html tags to put images
>> > into the relevant pages.
>>
>> I believe he has a full desktop client app, not a web app. Believe it or
>> not, there's still a solid place for desktop applications even in this
>> ever-increasing webified world.
>>
>> Use the right tool for the job...
> 
> There is no reason that something being a "desktop app" means they
> can't use HTTP instead of reinventing the protocol wheel all over
> again.

Absolutely! Which is why I recommended setting up an httpd to serve the 
images...

I interpreted Paul Rubin's response to say "rewrite the whole thing 
(client, server, everything) as a web app".

Cheers!


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why PHP is so much more popular for web-development

2007-07-25 Thread Paul McNett
Steve Holden wrote:
> When someone starts to push the limits of PHP they either continue to 
> push until they get where they want to be (producing an ugly or 
> ill-maintained bunch of code along the way) or they choose a more 
> appropriate tool.
> 
> The latter behavior is typical of programmers. The former is typical of 
> typical users. There are many people producing web sites who I wouldn't 
> let within yards of any of my code. but it's some kind of tribute to PHP 
> that it manages to satisfy so many of them. This doesn't mean that 
> grafting PHP features into Python mindlessly will improve the language.
> 
> The Python approach is a scalpel, which can easily cut your fingers off. 
> The PHP approach is a shovel, which will do for many everyday tasks.

Exactly right on. I actually use PHP quite a bit. For websites that 
would otherwise be static html pages other than the fact that I want to 
reuse elements (header, footer, etc.), I choose PHP in a heartbeat, 
because it's easy, and I'm lazy. Ditto if it is a simple db-driven site.

Start adding business rules and complex program flow and I run away from 
PHP as fast as I can. I wouldn't want to actually code anything in it, 
after all. ;)

I've seen comments that mod_python is hard to use, but I just haven't 
found that to be the case. For me, mod_python is the next step up when 
PHP no longer suits my needs. Granted, I'm spoiled because I run my own 
server and don't rely on some hosting provider to tell me what I can and 
cannot do. :)

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mouse control with ctypes in OS X

2007-08-20 Thread Paul McNett
Niklas Ottosson wrote:
> I need to get hold of the mouse position and also need to be able to 
> change it. In windows I have used ctypes.windll.user32.getCursorPos() 
> and ctypes.windll.user32.setCursorPos() with great success in my program 
> but now I also need to make a Mac OS X version of the program.
> 
> Does anyone know what the above libraries and functions are called in OS 
> X? Any help is greatly appreciated. 

All I can offer you is the knowledge that OS X will probably not let you 
set the mouse position, as it is a gross violation of the HIG (The user 
is in charge of where the mouse appears, not the application).

But, I'm sure someone will chime in on how to get the mouse position.

-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Dealing with PayPal's messy SPF records

2007-09-04 Thread Paul McNett
I administer email for a few clients of mine, using Postfix. One of the 
policies that is in place is SPF-checking, and rejecting messages 
accordingly. This has been working well for months.

However, today a user called me to complain that they weren't able to 
get confirmed with PayPal to set up a new account. Turns out, SPF was 
rejecting the email from PayPal because of "Too many DNS lookups". This 
was somewhat surprising as I had been expecting the problem to be with 
my greylisting setup.

I took a look at PayPal's SPF structure and it is indeed a big mess - 
lots of includes, and those includes have lots of hosts and mx records, 
etc.

I helped the user by temporarily disabling all SPF checking and then 
reenabling it after the user got confirmed, but I was wondering if there 
is an elegant way to tell postfix to "ignore the going over MAX_LOOKUPS" 
for ("paypal.com",). I guess this would involve modifying policyd-spf.py?

I took a look at the source spf.py, and see where these values are 
hardcoded, complete with references to the RFC, and I don't want to 
modify those hardcoded values. I also don't want to disable SPF as the 
final layer of policy checking on my mail server. But, I have to 
recognize that companies like PayPal are big players, and I'm probably 
not going to get them to budge by complaining, so I should try to 
accommodate their messy setups as much as possible, as my users are 
nearly always right.

Anyone been down this road before and can offer tips/advice? I did 
google for relevant strings, but didn't come up with anything that 
appeared to address this specific problem.


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Cron

2007-09-07 Thread Paul McNett
Greg Lindstrom wrote:
> This may be more of a Linux question, but I'm hoping some of you may be 
> able to help me.
> 
> I have a python (2.4) routine running on Gentoo Linux.  It creates a 
> file and, after the file is complete, renames the file using the 
> os.rename() command.  When I run the file from the command line 
> everything works great, but when I schedule the job to run from the 
> crontab file, the original file is created and populated, but the rename 
> fails.  I am using full paths for both the original and destination 
> file, and run the command line version after I 'su' to the production 
> account (named 'edith').  I am told by my sysadmin that the cron jobs 
> run as edith as well, so he does not think it is a permission issue (he 
> points out the original file is being created and populated as 
> expected...the rename fails)
> 
> Have any of you dealt with anything like this?  It really has me 
> scratching my head.

Can you post the Python script?

What's the name of the original file, and what are you trying to rename 
it to? I'm wondering if you are deriving the new name from something, 
and that thing is failing from within the cronjob for some reason. 
Perhaps the new name contains a complete path in one of the cases but 
not in the other...

Edith should be getting email (if email routing is set up correctly) if 
the job is failing or producing output. Specifically, perhaps she's 
getting Python tracebacks and not telling you... :)



-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File DB instead of real database?

2007-04-13 Thread Paul McNett
Jia Lu wrote:
>  I donot want to use a real DB like MySQL ... But I need something to
> save about more than 1000 articles.
>  Is there any good ways?

(in Python 2.5):

#-- begin
import sqlite3.dbapi2 as sqlite

con = sqlite.connect("path/to/new/filename.db")
cur = con.cursor()
cur.executescript("""
create table articles (id integer primary key autoincrement,
name text,
content clob);
create index articles_name on articles (name);

insert into articles (name, clob)
   values ("My new article", "Article text. blah blah");

""")

con.commit()

#-- end

-- 
pkm ~ http://paulmcnett.com

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


Re: How do you limit the # of lines Read?

2007-09-18 Thread Paul McNett
[EMAIL PROTECTED] wrote:
> I am working on a loop for my code and was wondering if there is a way
> to limit the number of lines read through?  I'd hate to cut the test
> file in order to run the code in the testing phase.  Can you add a
> value in the parenthesis of the readline() function?
> 
> t = string.readline()  # Limit this somehow?

Assuming s is a file-like object:

for idx, line in enumerate(s):
 if idx > 2:
 break
 print idx, line


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there some sort of portable IDE?

2007-09-24 Thread Paul McNett
Lamonte Harris wrote:
> Like say you don't got python installed, but you want to test code is 
> there a way?(School)

Like way, dude, check this out:
http://www.portablepython.com/



-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite and TemporaryFile under Windows

2007-10-15 Thread Paul McNett
Matthieu Brucher wrote:
> I want to create a temporary database that is downloaded for the net. So 
> I want to use a temporary file that will be deleted at the end of my 
> program. For this, I wanted to use tempfile.TemporaryFile. The problem 
> with Windows is that I can't give to sqlite3.connect() the file neither 
> can I give its name (if I use NamedTemporaryFile). Is there a solution 
> somewhere ?

Are you aware that you can do an in-memory database (IOW no file at all)?

cur = sqlite.connect(":memory:")


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite and TemporaryFile under Windows

2007-10-15 Thread Paul McNett
Matthieu Brucher wrote:
> Are you aware that you can do an in-memory database (IOW no file at
> all)?
> 
> cur = sqlite.connect (":memory:")
> 
> 
> Yes, but in this case, how can I use the DB that I downloaded from the net ?

Ah, sorry, I guess I missed that part.

> If this is the way of using sqlite, it is still cumbersome as a lot of 
> other classes that work on files can work on file-like (and isn't it the 
> whole point of Python ;) ?

I don't think that sqlite can work on streams, or on file-like objects.

You could just save it as tempfile.mktemp(). I think the utility of this 
function in this case outweighs the possibility that your routine will 
coincidentally overwrite another file of the same name within the same 
fraction of a second. The warning is dire, but when you think about it 
in context it doesn't seem that bloody likely that there will be a 
problem. ;)


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite and TemporaryFile under Windows

2007-10-16 Thread Paul McNett
Matthieu Brucher wrote:
>  > If this is the way of using sqlite, it is still cumbersome as a
> lot of
>  > other classes that work on files can work on file-like (and isn't
> it the
>  > whole point of Python ;) ?
> 
> I don't think that sqlite can work on streams, or on file-like objects.
> 
> 
> 
> Obviously it cannot, but what are the reason it can't ?

I have no idea.


> You could just save it as tempfile.mktemp(). I think the utility of this
> function in this case outweighs the possibility that your routine will
> coincidentally overwrite another file of the same name within the same
> fraction of a second. The warning is dire, but when you think about it
> in context it doesn't seem that bloody likely that there will be a
> problem. ;)
> 
> 
> Well, I could, but in this case I have to delete the file myself, which 
> the whole point of the use of TemporaryFile.

Go with the flow dude! Unless you want to solve the issue by delving in 
to the source for pysqlite yourself so that it can work on file-like 
object, the extra os.unlink call doesn't seem to be a big deal.

Also, you are downloading the file off the Internet somewhere anyway. 
Either you work with that stream without creating a file (which we've 
already discovered isn't possible) or you save it to a file. Sure, it 
would be nice to use TemporaryFile(), but it shouldn't be a showstopper 
to use mktemp() an unlink() instead.


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with format string / MySQL cursor

2007-10-18 Thread Paul McNett
[EMAIL PROTECTED] wrote:

> On Oct 19, 7:32 am, Florian Lindner <[EMAIL PROTECTED]> wrote:
>> Hello,
>> I have a string:
>>
>> INSERT INTO mailboxes (`name`, `login`, `home`, `maildir`, `uid`,
>> `gid`, `password`) VALUES (%s, %s, %s, %s, %i, %i, %s)
>>
>> that is passed to a MySQL cursor from MySQLdb:
>>
>> ret = cursor.execute(sql, paras)
>>
>> paras is:
>>
>> ('flindner', '[EMAIL PROTECTED]', '/home/flindner/', '/home/
>> flindner/Mail/test', 1001, 1001, '123')
>>
>> But that gives me an error:
>>
>> Traceback (most recent call last):
>>   File "account.py", line 188, in ?
>> main()
>>   File "account.py", line 33, in main
>> execute(action, account_type, options)
>>   File "account.py", line 129, in execute
>> executeSQL(sql, options.username, options.login, options.home,
>> options.directory, options.uid, options.gid, options.password)
>>   File "/home/flindner/common.py", line 29, in executeSQL
>> ret = cursor.execute(sql, paras)
>>   File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
>> 148, in execute
>> query = query % db.literal(args)
>> TypeError: int argument required
>>
>> I don't see errors in the format string or some other problem
>>
>> What's wrong?


> You should be using '?' for parameter bindings in your sql string not
> python format specifiers (you are after all writing sql here not
> python).
> 
> INSERT INTO mailboxes (`name`, `login`, `home`, `maildir`, `uid`,
> `gid`, `password`) VALUES (?, ?, ?, ?, ?, ?, ?)



Sorry Tim, but that isn't correct:

>>> import MySQLdb
>>> MySQLdb.paramstyle


'format'

Florian, what happens when you replace your %i with %s?


-- 
pkm ~ http://paulmcnett.com

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


Re: 3 number and dot..

2007-10-31 Thread Paul McNett
Abandoned wrote:

> Hi..
> I want to do this:
> for examle:
> 12332321 ==> 12.332.321
> 
> How can i do?


Assuming that the dots are always in the 3rd and 7th position in the string:

def conv(s, sep="."):
   l = [s[0:3], s[3:6], s[6:]]
   return sep.join(l)

print conv("12332321")


-- 
pkm ~ http://paulmcnett.com
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >