Re: MySql

2006-07-27 Thread Atanas Banov

[EMAIL PROTECTED] wrote:

 sorry guys...

 forget about the auto incrementer for a second.

 the entry is not being recorded. that is my problem. the script does
 not work. thanks.

after Dijkstra: the use of mySql cripples the mind; its teaching
should, therefore, be regarded as a criminal offence. 

thus said, which mysql engine are you using for your DB? is it
transactional, should you commit?

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


Re: Activating Batch Files from Python

2006-04-21 Thread Atanas Banov

Jeff Groves wrote:

 How would I do that? As I've said, I haven't found a Python command
 that lets you send multiple commands to the same shell yet. If I could,
 my problem would be solved.

any reason why you cannot create a temp .bat, consisting of:

setvar.bat
prog1.exe
prog2.exe

and then execute it form perl?

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


Re: multiline comments

2006-04-18 Thread Atanas Banov

Edward Elliott wrote:
 At the risk of flogging a dead horse, I'm wondering why Python doesn't have
 any multiline comments.  One can abuse triple-quotes for that purpose, but
 that's obviously not what it's for and doesn't nest properly.
...
 Saying coders shouldn't use multiline comments to disable code misses the
 point.  Coders will comment out code regardless of the existence of
 multiline comemnts.  There has to be a better argument for leaving them out.

i beg to differ: you'd be surprised how much effect can little
inconveniences have.

want to comment block of code? use tripple-quotes. does not nest? ahhh,
maybe it's time to get rid of that block you commented out a month ago
just in case the new code doesnt work.

that gives you incentive to tidy up. don't be a code slob... don't
leave a mess forever ;-)

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


Re: Characters contain themselves?

2006-04-07 Thread Atanas Banov

congratulations for (ostensibly) discovering the Barber's paradox (if
the village barber shaves all and only those who don't shave
tehmselves, who shaves the barber?
http://en.wikipedia.org/wiki/Barber_paradox) in python ! :-D

as far as i see it, you complaint is not just that any string X
contains itself but that string X can contain another string Y (i.e.
object of class string to contain another of class string) - where you
understand contain as per the operator in to be set-theory
operator, when in fact the meaning put for strings is instead has a
substring.

therefore your grudge is not just with
'a' in 'a'
but also with
'a' in 'abcd'

here is excerpt from the reference manual:

The operators in and not in test for set membership. x in s evaluates
to true if x is a member of the set s, and false otherwise. x not in s
returns the negation of x in s. The set membership test has
traditionally been bound to sequences; an object is a member of a set
if the set is a sequence and contains an element equal to that object.
However, it is possible for an object to support membership tests
without being a sequence. In particular, dictionaries support
membership testing as a nicer way of spelling key in dict; other
mapping types may follow suit.

For the list and tuple types, x in y is true if and only if there
exists an index i such that x == y[i] is true.

For the Unicode and string types, x in y is true if and only if x is a
substring of y. An equivalent test is y.find(x) != -1. Note, x and y
need not be the same type; consequently, u'ab' in 'abc' will return
True. Empty strings are always considered to be a substring of any
other string, so  in abc will return True.


it is apparent in was overriden for strings for convenience's sake,
not to get freaky on the therory of sets.

what can you do about it? well, you can check for string type
specifically but there are no guarantees in life: someone else can
define new type with in that behaves like that: say interval(x,y),
where interval(x,y) in interval(a,b) checks if [x,y] is a
sub-interval of [a,b] - very intuitive - but there you have the problem
again!

or you can specifically check if the objects are from a semanthically
supported group of classes - but that will hamper authomatic extension
by introducing new types.

- Nas

WENDUM Denis 47.76.11 (agent) wrote:
 While testing recursive algoritms dealing with generic lists I stumbled
 on infinite loops which were triggered by the fact that (at least for my
 version of Pyton) characters contain themselves.See session:

   'a' is 'a'
 True
   'a' in 'a'
 True
   'a' in ['a']
 True


 Leading to paradoxes and loops objects which contain themselves (and
 other kinds of monsters) are killed in set theory with the Axiom of
 Foundation:=)

 But let's go back to more earthly matters. I couldn't find any clue in a
 python FAQ after having googled with the following Python strings FAQ
 about why this design choice and how to avoid falling in this trap
 without having to litter my code everywhere with tests for stringiness
 each time I process a generic list of items.
 
 Any hints would be appreciated.

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


Re: Python equivalent of Perl-ISAPI?

2006-04-07 Thread Atanas Banov
it is your loss as well (so, 2 losses and 1 win).

you comparing perl-ex with python-cgi is unfair, to say the least.
let's count:

1. you ditched python ASP, because you dont know how it may port on
linux (even if it's supported on apache and you probably never, ever,
will have to do the said port).

2. you ditched mod_python, because it's for apache and not for IIS.

3. you picked perl-ex, because... it works fast on IIS, even if it
doesnt work on apache or linux.

hard to speak about fairness here. besides i guess your tests are based
on dummy script pages, which do nothing and the real pages which
interface with DB and equipment, will spend 10 times more time doing
real work, say 1500ms. now tell me what is the difference between 1.514
sec and 1.786 sec wait time? and even if that were not the case, what
is the diffrence for a user between 0.014 and 0.286 seconds? part of a
blink of the eye?!

- nas

 Din't find anything more and no further replies
 here so here is a quick timing I did...
   Perl-Ex:0.014 sec/page
   Perl-ISAPI: 0.168 sec/page
   Perl-cgi:   0.187 sec/page
   Python-cgi: 0.286 sec/page

 I can't ignore the 20X better performance of
 Perl-Ex vs Python, so I guess this is a loss
 for Python and a win for Perl.

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


Re: print() in Python 3000 return value?

2006-04-02 Thread Atanas Banov
James Thiele wrote:
 I noticed in PEP 3000 that print will become a function. The PEP
 references a thread where Guido explains this decision. The thread does
 not specify what the function will return. Has this been decided?

reading the discussion, the arguments are about print as of now being
a syntactic construc, an operator without apparent reason. all that is
proposed is to tuck it as a function/procedure, i.e. use parenthesis
and be able to redefine with a simple def print(...)

if you think about it, the pythonic way is for print to return None. we
use it for the side effect (stdout output)

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


Re: Python equivalent of Perl-ISAPI?

2006-03-20 Thread Atanas Banov

[EMAIL PROTECTED] wrote:
 Steve Holden wrote:
  [EMAIL PROTECTED] wrote:

   Pure cgi is too slow.  Active Scripting means ASP, yes?
   I need something that will do cgi scripts (a lot of which I already
   have
   and can modify but don't want to rewrite extensively, partly because
   of time issues, partly because I want to preserve some degree of
   portability back to a unix environment.).   I want something that does
   for IIS what mod_python does for apache.  Fastcgi looked scary even
   on unix plaforms, seems like an act of desperation on Windows,
  
  Yes, ASP is Active Scripting.
 
 Except I need cgi, not asp, for the reasons i gave.

it seems to me you have no clear idea what you need.

you say you have a lot of CGIs written but you don't clarify if that is
Python or Perl. since you look for python intergration, it seems they
are in python, however in previous posting you say you'll have to
revert to Perl for solution. it just doesnt make sense! if you use
Perl, you will have to REWRITE the scripts and if you do so, it's
unclear why wouldnt you use a superior technology like PHP/ASP/JSP -
any of those is way easier to manage.

it's also unclear why don't you use apache on windows, if mod_python is
your poison.

here is how i imagine you have the layers:
   [scripts (CGI?)]
   [glue]
   [web server (IIS?)]

where the discussion is about the glue between them. you say CGI is
too slow for you, so you will want something maintaining the CGI
programming model, but faster. this thing is called FastCGI - but you
are unhappy about it either. there is no way any perl glue can solve
your problem between your web server and your python scripts
whatsoever. you'll have to re-code the scripts for perl.

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


Re: why does close() fail miserably on popen with exit code -1 ?!

2006-02-21 Thread Atanas Banov
Jeffrey Schwab wrote:
 _PyPclose returns the exit status of the popened process (the popenee?),
 or -1 on error.  Of course, if the status is supposed to be -1, there's
 some confusion.

yes, that's what i thought the root of the problem is.

 In the snippet of code below (from Modules/posixmodule.c), result has
 been initialized to the output of fclose, which in your case is 0.  The
 comment is particularly handy.

...
   /* Indicate failure - this will cause the file object
* to raise an I/O error and translate the last
* error code from errno.  We do have a problem with
* last errors that overlap the normal errno table,
* but that's a consistent problem with the file object.
*/

the piece you quoted is from the unix #ifdef part, i think. there is
another version of the pypclose for windows below that.

in any event i think such behaviour is a bug - just because in unix
exit codes are limited to 0..255 (and returned multiplied by 256)
doesnt mean other OSes should suffer because of design flow in
_PyPclose, right?

throwing an IOError no error doesnt help.

is there a bug database for python where i can check if this was
discussed?

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


Re: why does close() fail miserably on popen with exit code -1 ?!

2006-02-20 Thread Atanas Banov

my gripe is about exit with MINUS ONE, not +1. see my post again.

yes, i know one cannot return -1 in unix (since returned value is
exitcode % 256 * 256), and no, i am not interested in unix behavior.

Rene Pijlman wrote:
 Atanas Banov:
 i ran onto this weirdness today: seems like close() on popen-ed
 (pseudo)file fails miserably with exception instead of returning exit
 code, when said exit code is -1.

 Not here.

 Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
 Type help, copyright, credits or license for more information.
  import os
  print os.popen('exit 1').close()
 1

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


Re: Multiplication optimization

2006-02-19 Thread Atanas Banov
Paul McGuire wrote:
 Does Python's run-time do any optimization of multiplication
 operations, like it does for boolean short-cutting?  That is, for a
 product a*b, is there any shortcutting of (potentially expensive)
 multiplication operations

no. and the reason is very simple: to the extent such optimization
makes sense, it has been done on assembler/CPU level already. i.e. when
the multiplication is mapped to the machine code
   IMUL  op
the Pentium processor would be smart enough not to do the work if AX or
the op are 0 or 1.

Python has no job trying to outsmart Intel (and the other chipmakers).
Boolean shortcuts are useful for entirely different reason, not speed.
e.g.
if lastDigit == 0 or i % lastDigit != 0:
break

if both operands of OR were to be evaluated, that would end up with
division-by-zero exception for lastDigit=0.

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


why does close() fail miserably on popen with exit code -1 ?!

2006-02-19 Thread Atanas Banov
i ran onto this weirdness today: seems like close() on popen-ed
(pseudo)file fails miserably with exception instead of returning exit
code, when said exit code is -1.

here is the simplest example (under Windows):

 print popen('exit 1').close()
1
 print popen('exit -1').close()
Traceback (most recent call last):
  File interactive input, line 1, in ?
IOError: (0, 'Error')
 print popen('exit -2').close()
-2

has anyone have idea why is that?

- nas

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


Re: commenting out blocks of code

2006-02-17 Thread Atanas Banov
Neil Hodgson wrote:
 Hi Steven,

  It is *easy* to detect when a line is already commented. It starts with a
  #. The ~ is superfluous.

 It is not usual to change a line from being code to being a comment
 as most lines of code make no sense as English text. If you do sometimes
 want to do this, the # key can be pressed at the beginning of a line.
 Ctrl+Q exists to allow commenting out sections of code that you do not
 want to be active. The ~ acts to differentiate these different uses of
 one language feature and makes it easy to apply the operation over
 ranges that include comments and then invert the operation.

hi.
here is something you both seems to have not considered: imagine you
make decision if ^Q has to comment or uncomment based on the 1st line
and not on each line individually in the block. so let's say i mark and
^Q this:
--
code1
#comment1
#comment2
code2


1st line is not commented, so i want to comment-out the whole blcok,
the result is
--
#code1
##comment1
##comment2
#code2


note how ## maintains where comments were. now, for the same selection,
^Q again? 1st character is #, so the editor is asked to uncomment,
dwim:
--
code1
#comment1
#comment2
code2


so there is a way to do it without #~ noise... now if we can only think
of how to do DWIM copypaste :-)!

- nas

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


Re: %SystemDrive%

2006-02-16 Thread Atanas Banov
Bryan Olson wrote:
 To get it with the \, you might use:

  os.path.abspath(os.environ['SYSTEMDRIVE'])

wrong!
the result is incorrect if the current directory is different from the
root.

 os.chdir(c:\\winxp)
 os.path.abspath(os.environ['SYSTEMDRIVE'])
'c:\\winxp'

if you really want it with backslash at the end, why not just add it

os.environ['SYSTEMDRIVE'] + '\\'

is it too simple?!

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


Re: %SystemDrive%

2006-02-15 Thread Atanas Banov
using
   os.chdir('/')
   os.getcwd()
is plain wrong in Windows.

what it does is change the current directory to root of the CURRENT
DRIVE (i.e. the drive of the directory where script was started from),
not the system drive. for example, if current directory was
c:\myscripts and system drive is d:, this will return c:\ and not d:\.
hence chdir doesnt do any good, you can do os.getcwd()[:3] with the
same success.

os.environ['SYSTEMDRIVE'] is the right way to go.
btw it correctly returns just drive letter and colon, a drive name
doesnt include [back]slash

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


Re: pop line from file

2006-02-15 Thread Atanas Banov
Sybren Stuvel wrote:

 If you're working on a UNIX platform, you could use FIFO pipes, see
 'mkfifo'.

named pipes exist on windows, see win32pipe.CreateNamedPipe

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


Re: Embedding an Application in a Web browser

2006-02-15 Thread Atanas Banov
paron wrote:
 I forgot -- I like the idea of Kerrigell, too. It runs on top of
 CherryPy, and lets you use python either in the server (which is just a
 little program on your local machine) or embedded in the html pages, or
 in a Kerrigell service, which is an application server based on Python.

oh sure, why make it simple, when we can make it difficult?!
your solution is like using a sledgehammer to crack a nut!

... I keep hearing the sound of nuts being pulverized...
http://www.bobcongdon.net/blog/2005/11/java-sledgehammer.html

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


Re: Embedding an Application in a Web browser

2006-02-14 Thread Atanas Banov

try this: create file named test.hta and put inside
-
HTML
BODY
SCRIPT LANGUAGE=Python

import sys
document.writeln(Hello from Python, sys.version)

/SCRIPT
/BODY
/HTML
-
double click to open it, it will work if you have activestate
extensions installed.

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


Re: Pythonic gui format?

2006-02-14 Thread Atanas Banov
ever considered doing the mapping this way?

window = [
  [item, {'k1': 'v1', 'k2': 'v2'],
  [otheritem, {'k1n': 'v1n', 'k2n': 'v2n'}]
]

it is as simple as it gets: for 1:1 mapping from XML, list of
Attributes becomes py List.
the list of Properties of an attribute becomes a py Dictionary

ps. you can do tuples instead of lists if immutable is ok.

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


Re: Python and ASP

2006-02-14 Thread Atanas Banov

Did you save it with .asp extension?
Is the directory enabled to run scripts?
Can you run any other server-side script snippet (say VBscript)?

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


Re: Soduku

2006-02-14 Thread Atanas Banov
you dont measure single run, you measure multiple runs using the
timeit module (for me 1000 repeats was about right).

here are some results which i recorded when i was implementing Sudoku
solver (on AMD Athlon 1.25GHz, using the sample shown on www.sudoku.com
front page):

brute:  1000 for 83 sec
smart:  1000 for 21 sec
brute, bitset:  1000 for  29 sec
smart, bitset:  1000 for  7.0 sec
smart, bit+que: 1000 for 5.3 sec

so you see the algorithm makes big difference... and so does the data
structure used. i got 15x speed-up that way. i guess i can claim that
my solver runs the sample for 5.3s/1000 = 5.3 ms!

a friend was also implementing sudoku - this time in C - and his
program solves the sample 1 times for 3.4sec (i.e. for 0.34ms) on
slightly faster machine - so let's say his **highly optimized** C code
is about 10x faster than mine.

- Nas

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


Re: processing limitation in Python

2006-02-14 Thread Atanas Banov
[EMAIL PROTECTED] wrote:
 But running it in IDLE just locks up the
 computer.  Bad Windows.

yeah, right - blame it all on Microsoft!

try ctrl-F6 (or Shell / Restart Shell from the menu) in IDLE, which
stops programs from infinite looping

- nas

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