Re: Output of HTML parsing

2007-06-15 Thread Sebastian Wiesner
[ Jackie <[EMAIL PROTECTED]> ]
> 1.The code above assume that each Prof has a tilte. If any one of them
> does not, the name and title will be mismatched. How to program to
> allow that title can be empty?
>
> 2.Is there any easier way to get the data I want other than using
> list?

Use BeautifulSoup.

> 3.Should I close the opened csv file("professor.csv")? How to close
> it?

Assign the file object to a separate name (e.g. stream) and then invoke its 
close method after writing all csv data to it.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: sqlite3 bug??

2007-06-17 Thread Sebastian Wiesner
[ Carsten Haese <[EMAIL PROTECTED]> ]
> On Sun, 2007-06-17 at 07:43 -0700, 7stud wrote:
> > Please report the whole docs as a bug.
>
> Calling the entire docs a bug is not helpful.

... unless he also comes up with the "bugfix". ;)

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: try/except/else/finally problem

2007-06-28 Thread Sebastian Wiesner
[ Ed Jensen <[EMAIL PROTECTED]> ]
> try:
> f = file('test.txt', 'r')
> except IOError:
> print 'except'
> else:
> print 'else'
> finally:
> print 'finally'
>
>
> And the results are:
>
>   File "./test.py", line 9
> finally:
>   ^
> SyntaxError: invalid syntax

A finally block isn't allowed to appear together with an except block for 
releases previous to 2.5. You need to split your exception handling into 
two separate blocks.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Building a Python app with Mozilla

2007-06-30 Thread Sebastian Wiesner
[ "Diez B. Roggisch" <[EMAIL PROTECTED]> ]
> And as it has been said in this thread already, Qt has an excellent free
> GUI-builder.

Free as long as you develop free software. Development of proprietary, 
non-gpl software with Qt requires a commercial licence from Trolltech.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: linecache and comparison with input

2007-06-30 Thread Sebastian Wiesner
[ Ross Hetherington <[EMAIL PROTECTED]> ]
> #!/usr/bin/env python
>
> import random
> import sys
> import linecache
>
> rnd = random.randint(1,3)
> line = linecache.getline('testfile', rnd)
>
> print line
Try print repr(line) ...
>
> gss = raw_input('Enter line: ',)
and print repr(gss) ;)

> if gss == line:
> print 'yes'
> sys.exit()
> else:
> print 'no'
>

Then you will see, that getline returns the line *including the newline 
character*, while raw_input does not.  Use line.strip('\n') to remove 
trailing newline characters from the return value of getline.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Building a Python app with Mozilla

2007-06-30 Thread Sebastian Wiesner
[ "Diez B. Roggisch" <[EMAIL PROTECTED]> ]
> > I'd like to build a Python GUI app. Neither Tkinter nor Wxpython nor
> > PyQT are actually what I want (because the lack of GUI builders and
> > they don't really look good on Windows and Linux).
>
> The latter statement is bogus. Qt is THE native look on KDE. GTK for
> Gnome. So how is it not "looking good on linux"?

I guess, "not looking good on linux" refers to Tkinter, which is in fact 
really ugly on linux systems.

> And as it has been said in this thread already, Qt has an excellent free
> GUI-builder. 

So have Gtk and WxWidgets.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The file executing

2007-07-03 Thread Sebastian Wiesner
[ Benjamin <[EMAIL PROTECTED]> ]
> On Jul 2, 9:47 pm, Justin Ezequiel <[EMAIL PROTECTED]>
>
> wrote:
> > On Jul 3, 9:40 am, Benjamin <[EMAIL PROTECTED]> wrote:
> > > How does one get the path to the file currently executing (not the
> > > cwd). Thank you
> >
> > os.path.dirname(sys.argv[0])
>
> The returns the file that was called first, but not the one currently
> executing...

Use __file__ instead of sys.argv[0]

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Emacs users: feedback on diffs between python-mode.el and python.el?

2008-10-17 Thread Sebastian Wiesner
At Thu, 16 Oct 2008 18:21:38 +0200 wrote Bruno Desthuilliers
<[EMAIL PROTECTED]>:
>>  It doesn't look like there's
>> any way to browse the subversion any more, though.
> 
> Doh :(
> 
> Is there any way to get this version then ???
svn co https://python-mode.svn.sourceforge.net/svnroot/python-mode/trunk/
python-mode


-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically generating arithmetic operations for a subclass

2009-04-14 Thread Sebastian Wiesner


> I have a subclass of int where I want all the standard arithmetic
> operators to return my subclass, but with no other differences:
> 
> class MyInt(int):
> def __add__(self, other):
> return self.__class__(super(MyInt, self).__add__(other))
> # and so on for __mul__, __sub__, etc.
> 
> 
> My quick-and-dirty count of the __magic__ methods that need to be over-
> ridden comes to about 30. That's a fair chunk of unexciting boilerplate.
> 
> Is there a trick or Pythonic idiom to make arithmetic operations on a
> class return the same type, without having to manually specify each
> method? I'm using Python 2.5, so anything related to ABCs are not an
> option.
> 
> Does anyone have any suggestions?

Metaclasses can be used for this purpuse, see the example for a Roman number 
type [1]

[1] http://paste.pocoo.org/show/97258/

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: pyqt4 qTableWidget add items help

2009-04-18 Thread Sebastian Wiesner
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



[...]
> I've been trying
> 
> while(len(orders)> i):
> ui.tb1_tblOrders.setCurrentCell(i,0,orders[i][1])
> i+=1
> 
> which to me, says go add in the first column row with the first order,
> and it makes sense to me
Read the documentation [1] to learn, what ".setCurrentCell()" actually does 
and what its arguments are!  And please stop this wild guessing ...

The method you're searching for is ".setItem()" [2], which adds a new 
QTableWidgetItem [3] to a QTableWidget. 

[1] http://doc.trolltech.com/4.5/qtablewidget.html#setCurrentCell
[2] http://doc.trolltech.com/4.5/qtablewidget.html#setItem
[3] http://doc.trolltech.com/4.5/qtablewidgetitem.html

- -- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)

iEYEARECAAYFAknpr4sACgkQGV4vxEMMOxdnawCfTXO55EffBJMQ7h91RGtMIpZ/
hcYAoLQ9yF5u/hBgNRvqxGRlIy5lPDgb
=Q6ef
-END PGP SIGNATURE-

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


Re: pyqt4 qTableWidget add items help

2009-04-19 Thread Sebastian Wiesner
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


> from PyQt4 import  ?? QtGui? QtCore? Those are already loaded   other
> options are pyqtconfig and uic and those don't sound correct...

from PyQt4 import QtGui
QtGui.QTableWidgetItem

See [1] for an example.

[1] 
http://hg.lunaryorn.de/snippets/file/3272fdd93736/qt4_table_header_alignment.py

- -- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)

iEYEARECAAYFAknrGyYACgkQGV4vxEMMOxceGQCgky6GtUAOlyKxLLYCBWGYhwez
2zoAmgN9OecHib4imoxyn/FsLGaEIDw6
=EIsK
-END PGP SIGNATURE-

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


Re: Presentation software for Python code

2009-04-24 Thread Sebastian Wiesner


> I'm willing to consider TeX- and HTML-based approaches.

I can recommend latex with the beamer package.  It doesn't directly support 
formatting of code snippets, but the pygments syntax highlighter comes with 
a Latex formatter.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: getting linux distro used...

2009-04-27 Thread Sebastian Wiesner


> In message  a88b-2ded6f8af...@y33g2000prg.googlegroups.com>, deostroll wrote:
> 
>> I just found that you could use platform.system() to get the
>> underlying os used. But is there a way to get the distro used...?
> 
> Mostly the differences will not be important. But if you want to know, I
> have been compiling a list of tests here
> 
.

At least the Gentoo-Test is not very reliable.  While "/usr/portage/" is the 
default location for the portage tree, it is not enforced, neither by 
portage nor by alternative package managers like paludis.  The portage tree 
as well as the distfiles can perfectly moved to another directory (I've done 
so).

Testing for the existing of "/usr/bin/emerge" or even better "/etc/gentoo-
release" seems more reliable to me.  The latter is also used by Python to 
implement "platform.dist()".

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: Question about the wording in the python documents.

2009-05-02 Thread Sebastian Wiesner

> I don't understand your objection. Is it that the documentation calls it
> Request instead of urllib2.Request? Or that it calls it an object instead
> of an instance?
I guess the latter ...

> In either case, I think you're picking a nit so small that it isn't
> actually there. All objects are instances (in Python), and all instances
> are objects.
Exactly, so strictly seen, "Request object" could possibly refer to the 
urllib2.Request class itself.  I guess, the OP would prefer the term 
"Request instance", emphasizing, that an instance of the request class has 
to be passed, not he class itself.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: Question about the wording in the python documents.

2009-05-02 Thread Sebastian Wiesner


> On May 2, 4:14 am, Sebastian Wiesner  wrote:
>> >
>> > In either case, I think you're picking a nit so small that it isn't
>> > actually there. All objects are instances (in Python), and all
>> > instances are objects.
>>
>> Exactly, so strictly seen, "Request object" could possibly refer to the
>> urllib2.Request class itself.  I guess, the OP would prefer the term
>> "Request instance", emphasizing, that an instance of the request class
>> has to be passed, not he class itself.
> 
> Yes, I personally think that the term "Request instance" would have
> made it much clearer to us people that have never taken a computer
> science class in our lives.

Btw, I should have said, that I don't share your objection:  Imho you don't 
need computer science lessons, but only common sense to understand, that 
passing the class object itself doesn't really make sense in this context ;)

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: LaTeXing python programs

2009-05-24 Thread Sebastian Wiesner


> On May 20, 10:10 pm, John Reid  wrote:
>> Alan G Isaac wrote:
>> > The listings package is great and highly configurable.
>> > Note that you can also input entire files of Python code
>> > or pieces of them based on markers.  Really quite great.
>>
>> I tried listings. I believe pygments makes better formatted output (at
>> least out of the box).
> 
> I'm trying to figure out how to use pygments. Are there any good usage
> examples out there?

It's not really difficult.   First choose a pygments style and create the 
latex definitions for it (STYLENAME serves as placeholder here):

pygmentize -S STYLENAME -f latex > pygments_style.tex

Now import the required packages and the style definitions:

\usepackage{color]
\usepackage{fancyvbr}
\input{pygments_style.tex}

These packages are included in Tetex as well as in Texlive, if not, you can 
of course install them from CTAN.

To format a snippet of code, run pygmentize and copy the output into your 
document:

pygmentize -f latex a_python_file.py

That's it.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: newbie: popen question

2009-05-28 Thread Sebastian Wiesner


> Your best bet is to make sudo not ask for a password.  :)  If you
> don't have the rights, then you can use pexpect to do what you want to
> do.  http://pexpect.sourceforge.net/pexpect.html
> 
> See the second example on that page.
> 
> child = pexpect.spawn('scp foo myn...@host.example.com:.')
> child.expect ('Password:')
> child.sendline (mypassword)

The sudo password prompt is very configurable, so changing the configuration 
to allow execution without password input is really the best option.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: Using C++ and ctypes together: a vast conspiracy? ;)

2009-06-02 Thread Sebastian Wiesner


> Diez B. Roggisch  wrote:
>>  Joseph Garvin schrieb:
>> > So I was curious whether it's possible to use the ctypes module with
>> > C++ and if so how difficult it is. I figure in principal it's possible
>> > if ctypes knows about each compiler's name mangling scheme. So I
>> > searched for "ctypes c++" on Google.
> [snip]
>> > More seriously -- how difficult is it to use ctypes instead of saying,
>> > boost::python, and why isn't this in a FAQ somewhere? ;)
>> 
>>  Because it's much more needed than name-mangling. Name mangling is
>>  (amongst other things) one thing to prevent
>>  C++-inter-compiler-interoperability which results from differing C++
>>  ABIs.
>> 
>>  I'm not an expert on this, but AFAIK no common ABI exists, especially
>>  not amongst VC++ & G++. Which means that to work for C++, ctypes would
>>  need to know about the internals of both compilers, potentially in
>>  several versions, and possibly without prior notice to changes.
> 
> Probably depends on how far you want to dig into C++.  I'm sure it
> will work fine for simple function calls, passing classes as anonymous
> pointers etc.  If you want to dig into virtual classes with multiple
> bases or the STL then you are probably into the territory you
> describe.

Name mangeling starts with namespaces, and namespaces are a thing often seen 
in well-designed C++-libraries.  So even a simple C++-function call could 
become rather difficult to do using ctypes ...

> That said I've used C++ with ctypes loads of times, but I always wrap
> the exported stuff in extern "C" { } blocks.

No wonder, you have never actually used C++ with C types.  An extern "C" 
clause tells the compiler to generate C functions (more precisely, functions 
that conform to the C ABI conventions), so effectively you're calling into 
C, not into C++.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: exit() or sys.exit()

2009-06-17 Thread Sebastian Wiesner


> What is the difference on exit() and sys.exit() when called in the
> main body of a script? From the command line they seem to have the
> same effect.

As of Python 2.5 there is no difference, however documentation [1] says 
about exit() and quit():

> They are useful for the interactive interpreter shell and should not be
> used in programs.

[1] http://docs.python.org/library/constants.html#constants-added-by-the-
site-module

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: Once again, comparison wxpython with PyQt

2009-06-18 Thread Sebastian Wiesner


> On Jun 18, 3:49 pm, "Diez B. Roggisch"  wrote:
>> Hans Müller wrote:
>> > Here we have to select between wxPython and PyQt for a medium size
>> > project. In this project several hundred dialogs are to be created.
>> > This work will be done by a program generator which has to re-written.
>>
>> > The question now is which framework should we use.
>> > As far as I could found is PyQt with the Qt Framework the superior
>> > choice. Most articles I found (not all) results to PyQt.
>> > But Qt is expensive ~ 3400€ per Developer and OS.
>>
>> No, it's not. It is LGPL by now.
>>
>> You will have to pay licensing for *PyQT*. I'm not sure, but I *think*
>> it's about 500€. However, it is much less than Qt used to be.
>>
>> Diez
> 
> Not quite. You only have to pay for the commercial license -- you can
> use PyQT as GPL as well.
FWIW, PyQt4 license conditions do not enforce GPL 2 for derived work, but 
also permit a bunch of other free software licenses (e.g. MIT/X11, BSD, 
Apache, etc.)

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: web frameworks that support Python 3

2009-08-23 Thread Sebastian Wiesner
At Sunday 23 August 2009 22:13:16 you wrote:
> I use Chinese and therefore Unicode very heavily, and so Python 3 is
> an unavoidable choice for me.
Python 2.x supports Unicode just as well as Python 3.  Every common web 
framework works perfectly with unicode.

In any case, there is bottle [1], which provides a *very minimal* framework 
for WSGI web development.  Don't expect too much, it is really small, and 
doesn't do much more than routing and minimal templating.

However, it is the only Python-3-compatible web framework I know of.

[1] http://bottle.paws.de/page/start

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list