getting local area connection information through python in windows

2010-05-22 Thread moijes12
Hi

I need to get the details of Local Area connection information(network
interface) like packets sent,packets recieved,duration etc. I have to
do this in Windows using python.

I tried looking under the socket module and also googling,but did not
find anything that I could use for windows,though I did find something
for linux.I have to somehow use the socket module for this.

Please help me in cracking this.

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


Re: where are the program that are written in python?

2010-05-22 Thread sturlamolden
On 21 Mai, 20:20, Patrick Maupin  wrote:

> There are a lot of commercial programs written in Python.  But any
> company which thinks it has a lock on some kind of super secret sauce
> isn't going to use Python, because it's very easy to reverse engineer
> even compiled Python programs.

Decompiling Java or .NET bytecode isn't rocket science either.


> Also, any company in a competitive
> market where execution speed is extremely important might choose some
> other language because, frankly, the fact that a development tool is
> highly productive is not something that the end user directly cares
> about.  

That only applies to CPU bound program code (most program code is I/O
bound), and only to computational bottlenecks (usually less than 5% of
the code) in the CPU bound programs. Today, most programs are I/O
bound: You don't get a faster network connection or harddrive by using
C. In this case, performance depends on other factors than choice of
language. That is why Mercurial (written in Python) can be much faster
than SVN (written in C).

For computational bottlenecks we might want to try high-performance
numerical libraries first. If that does not help, we can try to
replace some Python with C. Python as "glue" does not mean Python is
inferior to C. It just means it is a PITA to write C or Fortran all
the time. I value my own time a lot more than a few extra CPU cycles.
Who cares about speed where it is not needed?

There are also a lot of uneducated FUD about the GIL: First, for I/O
bound programs the GIL is not an issue, as threads that are blocked
and waiting for I/O do not compete for the GIL. (That should be rather
obvious, but my guesstimate is that most programmers do not understand
this.) Second, for CPU bound programs the GIL is not an issue either:
Fine-grained parallelization is done elsewhere than Python, e.g.
hidden inside numerical libraries or implemented with OpenMP pragmas
in C code. Course-grained parallelization can be done in Python using
Python threads, as the GIL can be released in C using a couple of
macros (or using ctypes.CDLL). In practice, the GIL rarely impairs
anything, but create a lot of FUD form persons who do not understand
the problem.

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


Re: getting local area connection information through python in windows

2010-05-22 Thread sturlamolden
On 22 Mai, 09:38, moijes12  wrote:

> I need to get the details of Local Area connection information(network
> interface) like packets sent,packets recieved,duration etc. I have to
> do this in Windows using python.


>>> import subprocess as sp

>>> p = sp.Popen("netstat -s", shell=False, bufsize=4096,
  stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)

>>> print ''.join(p.stdout.readlines())

>>> p.terminate()

There are other switches for the netstat command as well.

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


Re: getting local area connection information through python in windows

2010-05-22 Thread moijes12
On May 22, 1:12 pm, sturlamolden  wrote:
> On 22 Mai, 09:38, moijes12  wrote:
>
> > I need to get the details of Local Area connection information(network
> > interface) like packets sent,packets recieved,duration etc. I have to
> > do this in Windows using python.
> >>> import subprocess as sp
> >>> p = sp.Popen("netstat -s", shell=False, bufsize=4096,
>
>               stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
>
> >>> print ''.join(p.stdout.readlines())
> >>> p.terminate()
>
> There are other switches for the netstat command as well.

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


help with the Python 3 version of the decorator module

2010-05-22 Thread Michele Simionato
I have finally decided to port the decorator module to Python 3.
Changing the module was zero effort (2to3 worked) but changing the
documentation was quite an effort, since I had to wait for docutils/
pygements to support Python 3 and to change all my custom build
process. Also, I am relying on distribute for installing on Python 3.
I would welcome feedback for people using Python 3 on various
platforms (including Windows) to see if
they can install the module and how much of effort it is.

Here is the tarball: 
http://micheles.googlecode.com/files/decorator-3.2beta.tar.gz
Here is the documentation: 
http://micheles.googlecode.com/hg/decorator/index.html

The installation process should work for Python 2.4, 2.5, 2.6, 2.7,
3.0, 3.1 and all platforms were Python runs, but I have only tested it
on Linux for Python 2.6 and 3.1. The module has no relevant changes,
so I expect problems only from the building process, if any. I am not
sure of what will happen if you do not have distribute or if you have
a previous version of the module, or if you use pip or something else
(even in Python 2.X). The packaging in Python has become a real mess!

TIA for you help,

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


Urllib2: Only a partial page retrieved

2010-05-22 Thread Dragon Lord
I am trying to download a few IEEE pages by using urllib2, but with
certain pages I get only the first part of the page. With other pages
from the same server and url (just another pageID) I get the right
results. The difference between these pages seems to be the date the
paper for which the page is was published. Any papers from before 2000
end just before the date, pages from 2000 and later and at <\html>.

Two example URLs:

Does not work: http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=517048
Does work: http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=854728

I tried both urlopen and urlretrieve and tried both urllib and
urllib2. With urlopen I tried both .read() and .read(1) to make
sure I got the whole page, but nothing helped.
Sample code:

import urllib2
response = urllib2.urlopen("http://ieeexplore.ieee.org/xpl/
freeabs_all.jsp?arnumber=517048")
html = response.read()
print html

The cutoff is allways at the same location: just after the label
"Meeting date" and before the date itself. Could it be that something
is interpreted as and eof command or something like that?

example of the cutoff point with a bad page:
Meeting Date: 



example of the cutoff point with a good page:
Meeting Date: 


13 jun 2000

The bad pages do continue after this point btw. if you use a
webbrowser, it does not seem to be a server problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread Deep_Feelings
thank you very much ,your reply guys are very nice and informative.

hope you best luck in your life
-- 
http://mail.python.org/mailman/listinfo/python-list


help req setting breakpoints in gdb

2010-05-22 Thread sanam singh

Hi,
I am using wingide to debug my python code. To debug my c code
when i attach wingide to ddd. It is all done successfully. However when
i try to set a beak point in gdb i get following error :


(gdb) break /home/sa/mygr/gnuradio-core/src/lib/general/gr_gr_deinterleave.cc:13
No source file named 
/home/sa/mygr/gnuradio-core/src/lib/general/gr_gr_deinterleave.cc.

however the file really exists there.
Secondly, when after attach i simply give the command :
(gdb) break 13
Breakpoint 4 at 0x805a0f5: file ./Modules/python.c, line 13.

where as i am running my program from a different folder.
Please help me.
Cheers.
  
_
Hotmail: Trusted email with powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another "Go is Python-like" article.

2010-05-22 Thread Michele Simionato
On May 21, 4:20 pm, Grant Edwards  wrote:
>
> What about Go, exactly, do people see as Python-like?

The philosophy of keeping things simple. I find the concurrency
mechanism quite Pythonic.
Moreover Go interfaces are quite akin to Python duck typing, but
better. There also things which are quite different from Python e.g.
the attitude towards exceptions. In theory Go should be akin to C,
but my gut feeling is that in practice programming in it should not
feel too much different from
programming in Python (but I do not have first hand experience).

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


Re: creating addon system

2010-05-22 Thread timo verbeek
Is there not an other way to create a fast addon system?
A module or something like that
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: lfm v2.2

2010-05-22 Thread Iñigo Serna
Hi,

after 6 months of laziness while code was complete in my computer but
didn't have enough time, I'm releasing a new version of lfm now.


Description:
=
Last File Manager is a simple but powerful file manager for the UNIX
console. It's written in Python, using curses module.
Licensed under GNU Public License version 3.

Some of the features you could find in lfm:
- console-based file manager for UNIX platforms
- 1-pane or 2-pane view
- tabs
- bookmarks
- history
- vfs for compressed files
- dialogs with entry completion
- fast access to the shell
- direct integration of find/grep, df and other tools
- color files by extension
- fast file viewer with text and binary modes
- ...and many others


Download it from:
=
http://inigo.katxi.org/devel/lfm (home server)

or http://code.google.com/p/lfm/

or from http://www.terra.es/personal7/inigoserna/lfm when crap ISP
updates its cache.


Changes since last version:

  + New features
- use 2 progress bars in copy/move/delete dialog, one for files count
  and other for files size
- added recursive chmod chown chgrp
- faster cursor movement
  . Ctrl-l: center cursor in panel, so now edit-link is in 'L'
  . Ctrl-cursor_up, Ctrl-P: move cursor 1/4th of page up
  . Ctrl-cursor_down, Ctrl-N: move cursor 1/4th of page down
  . P: move cursor 1/4th of page up in other panel
  . N: move cursor 1/4th of page down in other panel
- file_menu new feature: a -> backup file. You can specify the extension
  to use in .lfmrc
- added support for .xz compressed files
- Unicode & Encodings
  . rewrite all internals to use unicode strings, but employ terminal
encoding (f.e. utf-8) to interact with the user or to display contents
in ncurses functions or to run commands in shell
  . when lfm detects a file with invalid encoding name it asks the user to
convert it (can be automatic with the proper option in the
configuration, automatic_file_encoding_conversion, default 0 (ask)).
If not converted, lfm will display the file but won't operate on it.
  . try more encodings when we get a filename with strange characters
  . lfm will check and require a valid encoding before running
- Pyview:
  . completely rewritten. Code is shorter and more beautiful now
Uses a new FileCache class to accelerate the retrieving of file lines
  . displays contents between 2 and 4 times faster
  . new command line flag -s/--stdin to force reading from stdin.
Now pyview doesn't wait for stdin input by default, so it starts much
faster. eg. $ ps efax | pyview -s

  + Minor changes
- add color entries for directories and exe_files
- expand ~ to user home
- make Tree follow .dotfiles behaviour, new keybinding Ctrl-H
- dialogs are bigger now
- show filesystem info rewritten
- show file info rewritten, now it shows correctly information
  from fuse-mounted volumes
- added new "ebook" category, filetypes and formats

  + About the code
- since python v2.6+, popen* is deprecated, so make lfm check python
  version and use popen* or subprocess accordingly
- correct some python idioms
- clean code

  + Documentation
- Added "Files Name Encoding" and "FAQ" sections
- Added information about keybindings in permissions window
- Updated some other minor changes: wide char support, vfs, thanks

  + lots of bugs fixed:
- file system information was not showed correctly sometimes
- devices major and minor numbers were not showed correctly
- crash in goto_dir if there aren't any historic entries
- crash in a void EntryLine after pressing BACKSPACE on some platforms
- unzip => overwrite files without prompting ("unzip -o" option) to avoid
  ethernal waiting, as messages can not be seen by user
- fix make_dir error message
- recompressing a vfs compressed file leave some garbage on temporary dir
- don't try to copy fifo/socket/block-dev/char-dev files
- crash when we don't have enough permissions to write to dest
- show_dirs_size: don't show in stderr if we don't have perms for a dir
- can't browse /home/ as root if .gvfs is present
- EntryLine: non-ascii chars are not showed correctly
- lfm crashes with invalid encoding filenames
- increment owner and group space to avoid ugly look in 1-pane view
- when moving files, don't delete source if some error or if we don't
  overwrite destination



Of course, all comments, suggestions, etc. are welcome.


Best regards,
Iñigo Serna
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread Tim Chase

On 05/22/2010 02:43 AM, sturlamolden wrote:

That only applies to CPU bound program code (most program code is I/O
bound), and only to computational bottlenecks (usually less than 5% of
the code) in the CPU bound programs. Today, most programs are I/O
bound: You don't get a faster network connection or harddrive by using
C. In this case, performance depends on other factors than choice of
language. That is why Mercurial (written in Python) can be much faster
than SVN (written in C).

For computational bottlenecks we might want to try high-performance
numerical libraries first. If that does not help, we can try to
replace some Python with C.


Just as an aside, last I checked, mercurial had some core code in 
C for speed.  But that doesn't negate your line of reasoning, 
rather it cements it -- they found it was most productive to work 
in Python, but needed the core bits to improve in speed so 
rewrote them in C.


I'd also include that a change in algorithm can be a big help for 
speeding up CPU-bound code.  It doesn't matter much if you're 
using Python or hand-coding that inner loop in C/ASM, if you're 
using a O(2^N) algorithm.  I find it easier to write good/speedy 
algorithms in Python because I have a toolkit of built-in 
data-types (sets, dicts, lists, etc) that I can reach for, 
without making sure I've added-on certain C libraries.


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


Re: Do any debuggers support "edit and continue?"

2010-05-22 Thread Fabio Zadrozny
On Wed, May 12, 2010 at 2:42 PM, Joel Koltner
 wrote:
> Just curious... in Microsoft's Visual Studio (and I would presume some other
> tools), for many languages (both interpreted and compiled!) there's an "edit
> and conitnue" option that, when you hit a breakpoint, allows you to modify a
> line of code before it's actually executed.
>
> Does any Python debugger support this feature?  Being an interpreted
> language it doesn't seem like it would necessarily be too onerous to
> support?  It'd be quite handy in that, especially if you hit a breakpoint
> due to the interpreter throwing an error, you could fix just the line in
> question and keep going, rather than having to stop the entire program, fix
> the line, and then run again and potentially kill a bunch of time getting
> the program back into the same "state."

Just for the record, Pydev had that from 1.4.8 to 1.5.5, but it was
removed because it could be a bit unpredictable (it relied on
xreload.py).

So, now what you can still do is change your variables / write any
code in the console / use the jump to re-execute something (in the
interface it's Run > Run to line -- or Ctrl+R) which is what you
usually need when experimenting (I still think the edit and continue
would be a nice feature, but the current state of xreload is not
really good for that -- and I'm not sure if it'll ever be -- although
I do have some alternatives in mind that would improve that support
greatly, some things could never be really fixed, such as changing the
value of an int constant that's been already assigned to somewhere
else -- anyways, I've got my hands on some other things right now, so,
there's currently no plan for that being supported (again)).

Cheers,

Fabio

p.s.: I think I'd be able to do it before reaching the whole $ 500,000
in funding :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another Strange MySQL Problem

2010-05-22 Thread Victor Subervi
On Fri, May 21, 2010 at 2:40 PM, Tim Chase wrote:

> On 05/21/2010 12:31 PM, Victor Subervi wrote:
>
>> cursor.execute('insert into Baggage values (Null, %s, %s, %s,
>> %s)', (flight_id, customer_id, weight, ticket_no))
>>
>
> You're trying to insert stuff...
>
>
>  OperationalError: (1452, 'Cannot add or update a child row: a foreign
>> key constraint fails (`seaflight/Baggage`, CONSTRAINT `Baggage_ibfk_2`
>> FOREIGN KEY (`customer_id`) REFERENCES `Customers` (`id`))')
>>
>
> But the value you're giving for the customer_id doesn't exist in the
> Customers table (as mandated by the FK).  Or perhaps the column-order for
> Baggage isn't what you think it is.  I always specify it explicitly:
>
>  INSERT INTO Baggage (
>   something, flight_id, customer_id, weight, ticket_no
>  ) VALUES (Null, %s, %s, %s, %s)
>
> just in case the table column-order ever changes during a database update.
>

As it turns out, my error was confusing my tables Customers and Passengers.
I was calling customer_id when I should have been calling passenger_id,
which is why MySQL couldn't find the correct values <:-}
beno

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


Re: creating addon system

2010-05-22 Thread Christian Heimes

Am 22.05.2010 12:06, schrieb timo verbeek:

Is there not an other way to create a fast addon system?
A module or something like that


How fancy are your requirements? People have written numerous plugin 
systems, from simple to use ones like CherryPy's tool system up to a 
complex component architecture like zope.component.


I recommend against exec() and execfile(). It makes debugging and 
testing harder and it has security concern, too.


Christian

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


Re: function that counts...

2010-05-22 Thread Bryan
I wrote:
> I came up with a recursive memo-izing algorithm that
> handles 100-digit n's.
[...]

I made a couple improvements. Code below.

-Bryan

#-

_nds = {}
def ndsums(m, d):
""" Count d-digit ints with digits suming to m.
"""
assert m >= 0 and d >= 0
m = min(m, d * 9 - m)   # exploit symmetry
if m < 0:
return 0
if m == 0 or d == 1:
return 1
if (m, d) not in _nds:
_nds[(m, d)] = sum(ndsums(m - i, d - 1)
   for i in range(min(10, m + 1)))
return _nds[(m, d)]


def prttn(m, n):
assert m >= 0 and n > 0
count = 0
dls = [int(c) for c in reversed(str(n))]
while dls:
msd = dls.pop()
count += sum(ndsums(m - d, len(dls)) for
d in range(min(msd, m + 1)))
m -= msd
return count


#--
# Testing

from bisect import bisect_right

def slow_prttn(m, n):
return sum(1 for k in range(m % 9, n, 9)
if sum(int(i) for i in str(k)) == m)

_sums = [0, {}]
def tab_prttn(m, n):
upto, sums = _sums
if n >= upto:
for i in range(upto, n):
dsum = sum(int(c) for c in str(i))
sums.setdefault(dsum, []).append(i)
_sums[0] = n
if m not in sums:
return 0
return bisect_right(sums[m], n - 1)

for n in range(1, 1234567):
digits = [int(c) for c in str(n)]
for m in range(9 * len(digits)):
count = tab_prttn(m, n)
assert prttn(m, n) == count
if n < 500:
assert slow_prttn(m, n) == count
if count == 0:
break
if n % 1000 == 0:
print('Tested to:', n)
-- 
http://mail.python.org/mailman/listinfo/python-list


Just To Be Sure...MySQL

2010-05-22 Thread Victor Subervi
Hi;
A lister recently responded to my post concerning mysl commands of the
following type:

cursor.execute('insert into foo values (%s, %s)' % (bar, something))

stating that I need to eliminate the "%" to prevent injection attacks, thus:

cursor.execute('insert into foo values (%s, %s)', (bar, something))

My question is simply this: Is that advice good for *all* mysql commands? Or
are there some where the "%" is necessary and a comma would fail? I need to
update lots of mysql commands. If I can do it without harmful consequences,
I'll do it across the board. Otherwise, I'll have to test each one.
TIA,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread Aahz
In article ,
Tim Chase   wrote:
>
>I'd also include that a change in algorithm can be a big help for  
>speeding up CPU-bound code.  It doesn't matter much if you're using
>Python or hand-coding that inner loop in C/ASM, if you're using a  
>O(2^N) algorithm.  

Rewriting an algorithm also helps I/O-bound code when you're doing
something stupid like querying a DB multiple times for each record
instead of caching the result.  Also, rewriting your algorithm to just
pull the entire DB into RAM helps, too.  (If you know your dataset must
fit into RAM, anyway, in order to process your algorithm.)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread sturlamolden
On 22 Mai, 17:09, a...@pythoncraft.com (Aahz) wrote:

> Rewriting an algorithm also helps I/O-bound code

Yes it does, if it involves how we do I/O. Algorithms are just as
important for I/O bound as they are for compute bound code.

But implementing an algorithm in C as opposed to Python would not
improve nearly as much for I/O bound as it could do for compute bound
code.







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


Re: Just To Be Sure...MySQL

2010-05-22 Thread Christian Heimes

A lister recently responded to my post concerning mysl commands of the
following type:

cursor.execute('insert into foo values (%s, %s)' % (bar, something))

stating that I need to eliminate the "%" to prevent injection attacks, thus:

cursor.execute('insert into foo values (%s, %s)', (bar, something))

My question is simply this: Is that advice good for *all* mysql commands? Or
are there some where the "%" is necessary and a comma would fail? I need to
update lots of mysql commands. If I can do it without harmful consequences,
I'll do it across the board. Otherwise, I'll have to test each one.
TIA,
beno


You *MUST NOT* use string formatting for SQL commands unless you 
carefully quote and validate the strings. Otherwise your SQL application 
is vulnerable to SQL injection attacks. SQL injections are one of the 
most common and devastating attacks for web applications these days.


Example:
"Select * from Users where uid = %s" % uid
uid = "1; DROP Table users;"

Guess what happens here ...


So yes, you must use the special syntax for all your commands. The DBA 
takes care of quoting. But you can't use the % replacement character for 
anything than the variable part of a DQL or DML statement. Variable 
parts are the right side of a WHERE, HAVING, SET and (IIRC) ORDER BY 
clause and the body of a VALUES block. But you can't do "Select * FROM %".


Christian

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


Re: Just To Be Sure...MySQL

2010-05-22 Thread Adam Tauno Williams
On Sat, 2010-05-22 at 18:06 +0200, Christian Heimes wrote:
> > A lister recently responded to my post concerning mysl commands of the
> > following type:
> >
> > cursor.execute('insert into foo values (%s, %s)' % (bar, something))
> >
> > stating that I need to eliminate the "%" to prevent injection attacks, thus:
> >
> > cursor.execute('insert into foo values (%s, %s)', (bar, something))
> >
> > My question is simply this: Is that advice good for *all* mysql commands? Or
> > are there some where the "%" is necessary and a comma would fail? I need to
> > update lots of mysql commands. If I can do it without harmful consequences,
> > I'll do it across the board. Otherwise, I'll have to test each one.
> > TIA,
> > beno
> 
> You *MUST NOT* use string formatting for SQL commands unless you 

+1

And they are hideous code.

Use an ORM: 

> carefully quote and validate the strings. Otherwise your SQL application 
> is vulnerable to SQL injection attacks. SQL injections are one of the 
> most common and devastating attacks for web applications these days.

-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: Just To Be Sure...MySQL

2010-05-22 Thread Christian Heimes

Am 22.05.2010 18:09, schrieb Adam Tauno Williams:

On Sat, 2010-05-22 at 18:06 +0200, Christian Heimes wrote:

A lister recently responded to my post concerning mysl commands of the
following type:

cursor.execute('insert into foo values (%s, %s)' % (bar, something))

stating that I need to eliminate the "%" to prevent injection attacks, thus:

cursor.execute('insert into foo values (%s, %s)', (bar, something))

My question is simply this: Is that advice good for *all* mysql commands? Or
are there some where the "%" is necessary and a comma would fail? I need to
update lots of mysql commands. If I can do it without harmful consequences,
I'll do it across the board. Otherwise, I'll have to test each one.
TIA,
beno


You *MUST NOT* use string formatting for SQL commands unless you


+1

And they are hideous code.

Use an ORM:


How about using a proper RDBMS that supports SQL standards, triggers, 
foreign keys and functions first? :)


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


Re: Urllib2: Only a partial page retrieved

2010-05-22 Thread Dragon Lord
Oops, het "Good" page is alos handled wrongly. The papers from 2000
are handled wrong too so a real example of a well performing page:

http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5206867

On May 22, 11:43 am, Dragon Lord  wrote:
> I am trying to download a few IEEE pages by using urllib2, but with
> certain pages I get only the first part of the page. With other pages
> from the same server and url (just another pageID) I get the right
> results. The difference between these pages seems to be the date the
> paper for which the page is was published. Any papers from before 2000
> end just before the date, pages from 2000 and later and at <\html>.
>
> Two example URLs:
>
> Does not work:http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=517048
> Does work:http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=854728
>
> I tried both urlopen and urlretrieve and tried both urllib and
> urllib2. With urlopen I tried both .read() and .read(1) to make
> sure I got the whole page, but nothing helped.
> Sample code:
>
> import urllib2
> response = urllib2.urlopen("http://ieeexplore.ieee.org/xpl/
> freeabs_all.jsp?arnumber=517048")
> html = response.read()
> print html
>
> The cutoff is allways at the same location: just after the label
> "Meeting date" and before the date itself. Could it be that something
> is interpreted as and eof command or something like that?
>
> example of the cutoff point with a bad page:
> Meeting Date: 
>
> example of the cutoff point with a good page:
> Meeting Date: 
>
>                                                                               
>   13 jun 2000
>
> The bad pages do continue after this point btw. if you use a
> webbrowser, it does not seem to be a server problem.

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


bash-style auto completion in command line program. use rlcomplete?

2010-05-22 Thread ntwrkd
I am trying to create a bash-style auto completion in a simple
command-line and script-based program i created using cmd.
I saw http://docs.python.org/library/rlcompleter.html, which I'm
thinking is the way to go for my program to intercept the tab key.
Would anyone have thoughts on this?

I wish cmd or cmd2 had this functionality built-in.

Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread Terry Reedy

On 5/21/2010 11:03 PM, Lie Ryan wrote:

On 05/22/10 04:47, Terry Reedy wrote:

On 5/21/2010 6:21 AM, Deep_Feelings wrote:

python is not a new programming language ,it has been there for the
last  15+ years or so ? right ?

however by having a look at this page
http://wiki.python.org/moin/Applications
i could not see many programs written in python (i will be interested
more in COMMERCIAL programs written in python ). and to be honest ,i


There are two kinds of 'commercial' programs.
1. The vast majority are proprietary programs kept within a company for
its own use. As long as these work as intended, they are mostly
invisible to the outside world.
2. Programs sold to anyone who wants them.

Python trades programmer speed for execution speed. If a successful
Python program is going to be run millions of times, it makes economic
sense to convert time-hogging parts to (for instance) C.  In fact, this
is a consideration in deciding what functions should be builtin and
which stdlib modules are written or rewritten in C.

Programs being sold tend to be compared to competitors on speed with
perhaps more weight than they rationally should. Speed is easier to
measure than, for instance, lack of bugs.


doubting python's speed?


The is a somewhat bizarre response to me. I have been promoting Python 
for about 13 years, since I dubbed it 'executable pseudocode', which is 
to say, easy to write, read, understand, and improve. I am also a 
realist. Any fixed (C)Python program can be sped up, at least a bit, and 
possibly more, by recoding in C. At minimum, the bytecodes can be 
replaced by the C code and C-API calls that they get normally get 
translated into. Ints can be unboxed. Etcetera. This tend to freeze a 
program, which is fine when development is finished.


I believe Raymond wrote each itertool (or at least most) in Python 
first, then rewrote each in C for speed, since they are intented to be 
repeatedly used components of other Python programs. He is not 'doubting 
Python's speed', just being realistic.


> Look at Mercurial vs. SVN;

Neither are being sold, as far as I know.


Mercurial is written in Python while SVN in C.

> Mercurial beats SVN in speed by several orders

of magnitude.


Because, as I said, and as you explain further, Python favors programmer 
speed, including speed of testing new algorithms, over raw execution 
speed of current algorithms. (Current) speed is (also) easier to test 
than improvability and hence possible speed improvements.


One of Mercurial's design goal was to be faster than SVN, if the
programmers have naively believed that choice of language would matter
to program's speed, they'd choose to write Mercurial in assembly instead
(the same argument applies to Git, written in shell scripts).

Now, you may think this is an unfair comparison, since Mercurial is hype
and new, SVN is antiquated and old. But it shows that in real-life, the
language being inherently slow often dosn't matter. What matters more
are the choice of data structure and algorithm, I/O speed, network
latency, and development speed.


If and when mercurial deveopment slows down, some of its developers 
might consider whether any of the utility functions written in Python 
might usefully be rewritten in C. One of the intentional virtues of 
Python is that one can transparently convert part or all of a module 
*without changing* the import and use of the module.


Terry Jan Reedy



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


Re: where are the program that are written in python?

2010-05-22 Thread Patrick Maupin
On May 22, 2:43 am, sturlamolden  wrote:
> On 21 Mai, 20:20, Patrick Maupin  wrote:

> > Also, any company in a competitive
> > market where execution speed is extremely important might choose some
> > other language because, frankly, the fact that a development tool is
> > highly productive is not something that the end user directly cares
> > about.  
>
> That only applies to CPU bound program code (most program code is I/O
> bound), and only to computational bottlenecks (usually less than 5% of
> the code) in the CPU bound programs. Today, most programs are I/O
> bound: You don't get a faster network connection or harddrive by using
> C. In this case, performance depends on other factors than choice of
> language. That is why Mercurial (written in Python) can be much faster
> than SVN (written in C).
>
> For computational bottlenecks we might want to try high-performance
> numerical libraries first. If that does not help, we can try to
> replace some Python with C. Python as "glue" does not mean Python is
> inferior to C. It just means it is a PITA to write C or Fortran all
> the time. I value my own time a lot more than a few extra CPU cycles.
> Who cares about speed where it is not needed?

I think we're in violent agreement here -- you neglected to quote the
part where I said "(But the up-front choice of another language simply
for speed, rather than prototyping with Python and then recoding the
slow bits, would probably be a decision borne of ignorance.)"

Regards,
Pat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another "Go is Python-like" article.

2010-05-22 Thread Patrick Maupin
On May 22, 5:00 am, Michele Simionato 
wrote:
> On May 21, 4:20 pm, Grant Edwards  wrote:
>
> > What about Go, exactly, do people see as Python-like?
>
> The philosophy of keeping things simple. I find the concurrency
> mechanism quite Pythonic.

That's nice.

> Moreover Go interfaces are quite akin to Python duck typing, but
> better.

That's nice too.

> There also things which are quite different from Python e.g.
> the attitude towards exceptions.

That's a biggie.  One of the beautiful things about Python is how it
lets me incrementally deal with incompletely specified problems --
"here's some source data -- go do something useful with it".  The FAQ
discusses why the go language deliberately leaves out assert -- the
developers rightly view assert statements as problematic in achieving
5 nines in a server environment, and they (somewhat incorrectly IMO)
view them as problematic when testing things.

Looking at their rationale, it is appears that one or more of the
primary go developers had to deal way too often with people who
overuse and abuse exceptions, so they are reverting to an almost
childish "I'll fix their little red wagon!  When they have to use *my*
language, they won't be able to do that anymore!" kind of mentality.
Another possibility is that they viewed the complexity of exceptions
as interfering with their primary goals, and felt it necessary to
rationalize their absence after the fact.

For some kinds of programming, the lack of exceptions wouldn't keep me
from programming Pythonically, but for huge classes of problems, it
would.  That's a big deal for me personally -- although I like to have
lots of tools in my toolbox, the one I reach for when doing
exploratory programming is probably going to have exceptions.  And
guess what?  If the exploratory programming winds up being "good
enough" (as often happens), then no recoding is required.

> In theory Go should be akin to C,
> but my gut feeling is that in practice programming in it should not
> feel too much different from
> programming in Python (but I do not have first hand experience).

For well-specified problems, I might be able to agree with you, but
I'm not sure.  Even then, sometimes I build stuff incrementally,
trying out various kinds of internal interfaces.  During that
development process, exceptions are a valuable mechanism for ensuring
that both sides of an interface agree on the contract.  (Obviously,
unit testing is useful in this as well, but premature unit testing can
add friction that makes it difficult to converge on an optimal design
-- it's no fun to be continually rearchitecting unit tests because of
other design decisions.)

What will be interesting to see is if a culture develops inside google
where people prototype in Python or some other language and then
implement the final cut in go.  If this happens often enough and the
cost of recoding the final implementation is deemed high enough, then
the natural question will be "What can we add to go to make it a
better prototyping language?"

Regards,
Pat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread Patrick Maupin
On May 22, 1:49 pm, Terry Reedy  wrote:

> Because, as I said, and as you explain further, Python favors programmer
> speed, including speed of testing new algorithms, over raw execution
> speed of current algorithms. (Current) speed is (also) easier to test
> than improvability and hence possible speed improvements.

First of all, I don't think you and Lie have any basic disagreements.
The key realization is that the quantitative difference in programmer
speed you mention is so large (orders of magnitude) that, for many
classes of problems, it is not just *possible*, but actually
*probable*, that a Python implementation *will be faster* than a C
implementation.  Yes, you are absolutely correct that most Python
programs can be made faster by adding a bit of C, but that doesn't
negate the fact that if I can throw 'x' man-hours at a problem, for
lots of real-world values of 'x' and of 'the problem', a pure Python
implementation will run rings around a pure C implementation, assuming
the C implementation even works by the time I've burned through 'x'
hours.  I discussed this a bit on this newsgroup over five years ago,
and the points are still pertinent:

http://groups.google.com/group/comp.lang.python/msg/910a54ddec946567

> If and when mercurial deveopment slows down, some of its developers
> might consider whether any of the utility functions written in Python
> might usefully be rewritten in C. One of the intentional virtues of
> Python is that one can transparently convert part or all of a module
> *without changing* the import and use of the module.

I don't even think that Mercurial development has to slow down to
decide to recode a few things in C.  A tiny bit of C at the right
place can often provide more than enough leverage to be worthwhile,
and be small enough to throw away if need be.

Regards,
Pat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread Patrick Maupin
On May 21, 10:30 pm, Chris Rebert  wrote:

> Erm, in fairness, I recall hearing that some speed-critical bits of hg
> are written in C. It does lend credence to the "Python as glue
> language" argument though; I doubt hg's extensibility and friendly
> interface would have been as easy to implement it C (particularly the
> slick instant-server feature).

Is C viewed as a "glue language" in those environments where it is the
primary tool and sometimes some small bits are recoded into assembly
language for speed?

Regards,
Pat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bash-style auto completion in command line program. use rlcomplete?

2010-05-22 Thread member thudfoo
On Sat, May 22, 2010 at 11:01 AM, ntwrkd  wrote:
> I am trying to create a bash-style auto completion in a simple
> command-line and script-based program i created using cmd.
> I saw http://docs.python.org/library/rlcompleter.html, which I'm
> thinking is the way to go for my program to intercept the tab key.
> Would anyone have thoughts on this?
>
> I wish cmd or cmd2 had this functionality built-in.
>

It is built in. Check the cmd documentation for complete_* method of Cmd class.

Following is an example of it use for a command called "open":

def complete_open(self, text, line, begidx, endidx):
asmfiles = glob('%s/*.asm' % ASMDIR)
matches = []
for path in asmfiles:
fname = os.path.basename(path)
if fname.startswith(text):
matches.append(fname)
return matches
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread Adam Tauno Williams
On Fri, 2010-05-21 at 11:20 -0700, Patrick Maupin wrote:
> On May 21, 5:21 am, Deep_Feelings  wrote:
> > 2- python is high productivity language : why there are no commercial
> > programs written in python ?
> There are a lot of commercial programs written in Python.  But any
> company which thinks it has a lock on some kind of super secret sauce
> isn't going to use Python, 

Is it [only] the aspect of being "sold" that makes software
"commercial"?

A better question would be is how many Python applications, in house or
not, are used to facilitate commerce.  Answer: a lot.

I have an Open Source project with >100,000 lines of Python code [which
I think qualifies as a 'real' application]
.  But that it is Open
Source makes it non-commercial?  I doubt anyone would use it outside of
a commercial environment, and one of its principle goals is to serve as
the backend for CRM systems [essentially commercial] and facilitate
automation of business processes [essentially commercial].  The 'secret
sauce' isn't the code [which is MIT licenses] but what you do with it.
But since the framework is essentially general purpose - why not publish
the code?

I think of my Open Source code as "commercial".

-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: Just To Be Sure...MySQL

2010-05-22 Thread Aahz
In article ,
Christian Heimes   wrote:
>
>You *MUST NOT* use string formatting for SQL commands unless you 
>carefully quote and validate the strings. Otherwise your SQL application 
>is vulnerable to SQL injection attacks. SQL injections are one of the 
>most common and devastating attacks for web applications these days.
>
>Example:
>"Select * from Users where uid = %s" % uid
>uid = "1; DROP Table users;"
>
>Guess what happens here ...

http://xkcd.com/327/

(Just in case there are newbies here.)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another "Go is Python-like" article.

2010-05-22 Thread Steven D'Aprano
On Sat, 22 May 2010 12:13:30 -0700, Patrick Maupin wrote about the lack 
of exceptions in Go:

> Looking at their rationale, it is appears that one or more of the
> primary go developers had to deal way too often with people who overuse
> and abuse exceptions, so they are reverting to an almost childish "I'll
> fix their little red wagon!  When they have to use *my* language, they
> won't be able to do that anymore!" kind of mentality. Another
> possibility is that they viewed the complexity of exceptions as
> interfering with their primary goals, and felt it necessary to
> rationalize their absence after the fact.

That's two possible explanations. A third is that they genuinely believe 
that exceptions lead to poor programming practice and left them out, just 
as the designers of many other languages believe that goto leads to poor 
practice and leave it out as well.

I don't think there's necessarily anything "childish" about choosing to 
leave out a language feature that you think is bad from a language you 
design.


Indeed, when I design my killer language, the identifiers 
"foo" and "bar" will be reserved words, never used, and not 
even mentioned in the reference manual. Any program using 
one will simply dump core without comment. Multitudes will 
rejoice. -- Tim Peters, 29 Apr 1998



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


Help (I can't think of a better title)

2010-05-22 Thread Lanny
The answer may be right infront of me but I really can't figure this
out.
I'm trying to build a interactive fiction kind of game, silly I know
but I
am a fan of the genre. I'm trying to build up an index of all the
rooms in
the game from an outside file called roomlist.txt. The only problem is
that
every room ends up having four exits. Here's the code.


class room() :
room_id = 'room_id'
name = 'room'
description = 'description'
item_list =
exits = {}
visits = 0
def leave(self, direction)
global roomlist
global player_current_room
if direction not in player_current_room.exitskeys() :
print 'There is no exit in that direction.'
return 1
roomlist[self.room_id] = self
player_current_room =
roomlist[player_current_room.exits[direction]]
print player_current_room.name
if player_current_room.visits < 1 :
print player_current_room.description
if player_current_room.item_list != [] :
stdout.write('You can see ')
for item in player_current_room.item_list :
stdout.write('a')
if item.display_name[0] in ['a','e','i','o','u'] :
 stdout.write('n ' + item.display_name
+
',')
else :
stdout.write(item.display_name + ',')
pass

print
print 'Exits:',
for way in player_current_room.exits :
print way.capitalize(),
print
player_current_room.visits += 1
pass
else :
player_current_room.visits += 1
pass
pass

def build_rooms(room_file) :
global roomlist
rfile = open(room_file)
tmp_builder = ''
for line in rfile :
tmp_builder = tmp_builder + line[:-1]
pass
for location in tmp_builder.rsplit('::') :
if location.rsplit(';')[-1] == '' :
location = location[:-1]
if len(location.rsplit(';')) != 5 :
if '-dev' or '-v' in argv :
print location.rsplit(';')[0], 'had',
len(location.rsplit(';')), 'values in it, 5 expected'
for value in location.rsplit(';') :
print; print value
foobar.append(value)
print 'A room failed to initalize due to either too
much or
not enough values being present in the build file'
pass
pass
else :
roomlist[location.rsplit(';')[0]] = room()
roomlist[location.rsplit(';')[0]].room_id =
location.rsplit(';')[0]
roomlist[location.rsplit(';')[0]].name =
location.rsplit(';')[1]
roomlist[location.rsplit(';')[0]].description =
location.rsplit(';')[2]
if location.rsplit(';')[3] != 'none' :
pass
tmp_var = location.rsplit(';')[4]
print location.rsplit(';')[0],
roomlist[location.rsplit(';')[0]].exits, 'before'
for way in tmp_var.rsplit(',') :
roomlist[location.rsplit(';')[0]].exits[way.rsplit(':')
[0]]
= way.rsplit(':')[1]

roomlist = {}
build_rooms('room_list.txt')

And here is the roomlist.txt file :

start_room;
Starting Room;
This is the starting room, if you can read this text it means that at
least
one part of this beta is working.;
none;
north:second_room,west:aux_room;
::
second_room;
Second Room;
Yo, Yo! This is the second room, if you can see this text a
substantitally
greater amount of the game is running than would have been if you
didn't see
this text.;
apple;
south:start_room;
::
aux_room;
Auxillary Room;
No, there aren't any barbarian conscripts here, but there is a table!;
none;
east:start_room;

Ideally roomlist['start_room'].exits would equal {'aux_room' :
'west',
'second_room' : 'north'} but it doesn't. Sorry if this is unclear or
too
long, but I'm really stumped why it is giving bad output
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help (I can't think of a better title)

2010-05-22 Thread MRAB

Lanny wrote:

The answer may be right infront of me but I really can't figure this
out.
I'm trying to build a interactive fiction kind of game, silly I know
but I
am a fan of the genre. I'm trying to build up an index of all the
rooms in
the game from an outside file called roomlist.txt. The only problem is
that
every room ends up having four exits. Here's the code.


class room() :
room_id = 'room_id'
name = 'room'
description = 'description'
item_list =
exits = {}

> visits = 0

These attributes are being defined as belonging to the class, so they
will be shared by all the instances of the class. This isn't a problem
for immutable items such as strings, but is for mutable items such as
dicts. In short, all the rooms share the same 'exits' dict.

You should really define the instance attributes (variables) in the
'__init__' method.


def leave(self, direction)
global roomlist
global player_current_room
if direction not in player_current_room.exitskeys() :
print 'There is no exit in that direction.'
return 1
roomlist[self.room_id] = self
player_current_room =
roomlist[player_current_room.exits[direction]]
print player_current_room.name
if player_current_room.visits < 1 :
print player_current_room.description
if player_current_room.item_list != [] :
stdout.write('You can see ')
for item in player_current_room.item_list :
stdout.write('a')
if item.display_name[0] in ['a','e','i','o','u'] :
 stdout.write('n ' + item.display_name
+
',')
else :
stdout.write(item.display_name + ',')
pass

print
print 'Exits:',
for way in player_current_room.exits :
print way.capitalize(),
print
player_current_room.visits += 1
pass
else :
player_current_room.visits += 1
pass
pass

def build_rooms(room_file) :
global roomlist
rfile = open(room_file)
tmp_builder = ''
for line in rfile :
tmp_builder = tmp_builder + line[:-1]
pass
for location in tmp_builder.rsplit('::') :
if location.rsplit(';')[-1] == '' :
location = location[:-1]
if len(location.rsplit(';')) != 5 :
if '-dev' or '-v' in argv :
print location.rsplit(';')[0], 'had',
len(location.rsplit(';')), 'values in it, 5 expected'
for value in location.rsplit(';') :
print; print value
foobar.append(value)
print 'A room failed to initalize due to either too
much or
not enough values being present in the build file'
pass
pass
else :
roomlist[location.rsplit(';')[0]] = room()
roomlist[location.rsplit(';')[0]].room_id =
location.rsplit(';')[0]
roomlist[location.rsplit(';')[0]].name =
location.rsplit(';')[1]
roomlist[location.rsplit(';')[0]].description =
location.rsplit(';')[2]
if location.rsplit(';')[3] != 'none' :
pass
tmp_var = location.rsplit(';')[4]
print location.rsplit(';')[0],
roomlist[location.rsplit(';')[0]].exits, 'before'
for way in tmp_var.rsplit(',') :
roomlist[location.rsplit(';')[0]].exits[way.rsplit(':')
[0]]
= way.rsplit(':')[1]

roomlist = {}
build_rooms('room_list.txt')

And here is the roomlist.txt file :

start_room;
Starting Room;
This is the starting room, if you can read this text it means that at
least
one part of this beta is working.;
none;
north:second_room,west:aux_room;
::
second_room;
Second Room;
Yo, Yo! This is the second room, if you can see this text a
substantitally
greater amount of the game is running than would have been if you
didn't see
this text.;
apple;
south:start_room;
::
aux_room;
Auxillary Room;
No, there aren't any barbarian conscripts here, but there is a table!;
none;
east:start_room;

Ideally roomlist['start_room'].exits would equal {'aux_room' :
'west',
'second_room' : 'north'} but it doesn't. Sorry if this is unclear or
too
long, but I'm really stumped why it is giving bad output


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


Re: Help (I can't think of a better title)

2010-05-22 Thread Alex Hall
On 5/22/10, MRAB  wrote:
> Lanny wrote:
>> The answer may be right infront of me but I really can't figure this
>> out.
>> I'm trying to build a interactive fiction kind of game, silly I know
>> but I
>> am a fan of the genre. I'm trying to build up an index of all the
>> rooms in
>> the game from an outside file called roomlist.txt. The only problem is
>> that
>> every room ends up having four exits. Here's the code.
>>
>>
>> class room() :
>> room_id = 'room_id'
>> name = 'room'
>> description = 'description'
>> item_list =
>> exits = {}
>  > visits = 0
>
> These attributes are being defined as belonging to the class, so they
> will be shared by all the instances of the class. This isn't a problem
> for immutable items such as strings, but is for mutable items such as
> dicts. In short, all the rooms share the same 'exits' dict.
>
> You should really define the instance attributes (variables) in the
> '__init__' method.

I just ran into something similar to this in my Battleship game. I had
a Craft class, which defined attributes for any craft (a recon plane,
a submarine, a battleship, and so on). One such attribute was a
weapons list, much like your exits dictionary; I would assign a couple
weapons to a battleship, but suddenly all my ships and airplanes had
those same weapons. What the great people on this list said to do was
something like this:

class Room():
 def __init__(self, exits):
  if exits==None:
   self.exits={}
  else:
   self.exits=exits

In this way, you can create a new Room object with exits,
r=Room(exits_dict)
or you can create a Room with no exits, and add them later:
r2=Room()
r2.exits["exit1"]="doorway"

but the code in the __init__ method, which will get called as soon as
you create a new Room object, ensures that passing an exits dictionary
will set that instance's exits to what was passed in, while passing
nothing will create a room with an empty dictionary (the if
statement). I hope this made some sense!
>
>> def leave(self, direction)
>> global roomlist
>> global player_current_room
>> if direction not in player_current_room.exitskeys() :
>> print 'There is no exit in that direction.'
>> return 1
>> roomlist[self.room_id] = self
>> player_current_room =
>> roomlist[player_current_room.exits[direction]]
>> print player_current_room.name
>> if player_current_room.visits < 1 :
>> print player_current_room.description
>> if player_current_room.item_list != [] :
>> stdout.write('You can see ')
>> for item in player_current_room.item_list :
>> stdout.write('a')
>> if item.display_name[0] in ['a','e','i','o','u'] :
>>  stdout.write('n ' + item.display_name
>> +
>> ',')
>> else :
>> stdout.write(item.display_name + ',')
>> pass
>>
>> print
>> print 'Exits:',
>> for way in player_current_room.exits :
>> print way.capitalize(),
>> print
>> player_current_room.visits += 1
>> pass
>> else :
>> player_current_room.visits += 1
>> pass
>> pass
>>
>> def build_rooms(room_file) :
>> global roomlist
>> rfile = open(room_file)
>> tmp_builder = ''
>> for line in rfile :
>> tmp_builder = tmp_builder + line[:-1]
>> pass
>> for location in tmp_builder.rsplit('::') :
>> if location.rsplit(';')[-1] == '' :
>> location = location[:-1]
>> if len(location.rsplit(';')) != 5 :
>> if '-dev' or '-v' in argv :
>> print location.rsplit(';')[0], 'had',
>> len(location.rsplit(';')), 'values in it, 5 expected'
>> for value in location.rsplit(';') :
>> print; print value
>> foobar.append(value)
>> print 'A room failed to initalize due to either too
>> much or
>> not enough values being present in the build file'
>> pass
>> pass
>> else :
>> roomlist[location.rsplit(';')[0]] = room()
>> roomlist[location.rsplit(';')[0]].room_id =
>> location.rsplit(';')[0]
>> roomlist[location.rsplit(';')[0]].name =
>> location.rsplit(';')[1]
>> roomlist[location.rsplit(';')[0]].description =
>> location.rsplit(';')[2]
>> if location.rsplit(';')[3] != 'none' :
>> pass
>> tmp_var = location.rsplit(';')[4]
>> print location.rsplit(';')[0],
>> roomlist[location.rsplit(';')[0]].exits, 'before'
>> for way in tmp_var.rsplit(',') :
>> roomlist[location.rsplit(';')[0]].exits[way.rsplit(':')
>> [0]]
>> = way.rsplit(':')[1]
>>
>> roomlist = {}
>> build_rooms('room_list.txt')
>>
>> And here is 

Re: Another "Go is Python-like" article.

2010-05-22 Thread Patrick Maupin
On May 22, 6:14 pm, Steven D'Aprano  wrote:
> On Sat, 22 May 2010 12:13:30 -0700, Patrick Maupin wrote about the lack
> of exceptions in Go:
>
> > Looking at their rationale, it is appears that one or more of the
> > primary go developers had to deal way too often with people who overuse
> > and abuse exceptions, so they are reverting to an almost childish "I'll
> > fix their little red wagon!  When they have to use *my* language, they
> > won't be able to do that anymore!" kind of mentality. Another
> > possibility is that they viewed the complexity of exceptions as
> > interfering with their primary goals, and felt it necessary to
> > rationalize their absence after the fact.
>
> That's two possible explanations. A third is that they genuinely believe
> that exceptions lead to poor programming practice and left them out, just
> as the designers of many other languages believe that goto leads to poor
> practice and leave it out as well.
>
> I don't think there's necessarily anything "childish" about choosing to
> leave out a language feature that you think is bad from a language you
> design.

While I admit that "childish" is an inflammatory simplification, other
than that, I think that your possible explanation is, essentially,
identical to my first possibility -- why would you think exceptions
were bad if you didn't have first-hand evidence of that?

Regards,
Pat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are the program that are written in python?

2010-05-22 Thread Gregory Ewing

Deep_Feelings wrote:

i will be interested more in COMMERCIAL programs written in python


I came across a game on Big Fish Games recently (it was
"The Moonstone" IIRC) that appeared to have been built using
Python and py2app.

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


Re: Reading data from a Microsoft Access 2003 database

2010-05-22 Thread Gregory Ewing

On Thu, 20 May 2010 02:45:10 -0700 (PDT), Jimoid
 declaimed the following in
gmane.comp.python.general:


I've now had a closer look at both pyODBC and mxODBC and it seems to
me that they both require the database to be running to be able to
query it. Is this correct?


If you mean that an instance of MS Access has to be running,
no, I don't think so. The ODBC driver for Access databases
knows how to open .mdb files itself. I've done this myself
recently, and it seems to work fine without having Access
running anywhere.

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


Re: where are the program that are written in python?

2010-05-22 Thread sturlamolden
On 22 Mai, 20:45, Patrick Maupin  wrote:

> I think we're in violent agreement here -- you neglected to quote the
> part where I said "(But the up-front choice of another language simply
> for speed, rather than prototyping with Python and then recoding the
> slow bits, would probably be a decision borne of ignorance.)"

I'm not arguing against you. You're argument is almost that which
Donald Knuth attributes to C.A.R. Hoare: "Premature optimization is
the root of all evil in computer programming." It's very true though.

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


Re: where are the program that are written in python?

2010-05-22 Thread sturlamolden
On 22 Mai, 13:28, Tim Chase  wrote:

> Just as an aside, last I checked, mercurial had some core code in
> C for speed.  

I've been writing scrintific software for over 10 years. I always find
myself writing small pieces of C now and then. It is usally because
header files are too complicated to expose to Python. I will e.g. make
OpenGL calls from C, and then call the rendering routine from Python
with ctypes. It saves me the work of exposing OpenGL (or whatever) to
Python. There are already header files that make the API available to
C.

Yes I know about PyOpenGL, but then there is the speed argument: From
C I can make epeated calls to functions like glVertex4f with minial
loss of efficacy. Calling glVertex4f from Python (e.g. PyOpenGL) would
give me the Python (and possibly ctypes) overhead for each call, which
is considerable.

So there is the two arguments for using C now and then: (1) Save
programming time by not having to repeat header files and (2) make
programs run faster by avoiding the Python overhead. Some times it
matters, some times it don't. But it does not make sense to write C or
C++ all the time, nor does it help to use C or C++ for I/O bound
problems.








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


Re: where are the program that are written in python?

2010-05-22 Thread Xavier Ho
On Sun, May 23, 2010 at 3:35 PM, sturlamolden  wrote:

> Yes I know about PyOpenGL, but then there is the speed argument: From
> C I can make epeated calls to functions like glVertex4f with minial
> loss of efficacy. Calling glVertex4f from Python (e.g. PyOpenGL) would
> give me the Python (and possibly ctypes) overhead for each call, which
> is considerable.
>

Not to counter your arguement, but I would just like to point out that
calling glVertex*() repeatedly is always not as efficient as using a VBO or
a display list.

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list