PEP 572 -- Assignment Expressions

2018-11-27 Thread Ivo Shipkaliev
   Hello.
   Maybe it's too late for a discussion, but I just couldn't resist.
   I just found out about this new ":=" operator. I need to ask:

   What is the need for this additional ":" to the "="?
   Why:
 if (match := pattern.search(data)) is not None:
   # Do something with match

   What is wrong with:
 if match = pattern.search(data) is not None:
   # Do something with match

   Assignment expression or assignment statement, it's an assignment,
right? It is very clear to everyone that it's an assignment! Can't it all
just be a "="?
   Thank you very much!


   Kind Regards
   Ivo Shipkaliev
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python.NET question?

2017-03-21 Thread Ivo Bellin Salarin
IronPython?

Le mar. 21 mars 2017 08:52, Tristan B. Kildaire  a
écrit :

> Is Python.NET a version of Python that compiles Python source code to
> Microsoft's IR for running by a MS runtime?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Python doesn't catch exceptions ?

2017-02-01 Thread Ivo Bellin Salarin
Hi all,

I have a curious problem with Python exceptions.

The following code doesn't catch HttpError:
```
from server.libs.googleapiclient.errors import HttpError
[..]
try:
OAuth.backoffExec(request)
return True
except HttpError as e:
return e.resp.status == 404
except Exception as e:
import inspect
import os
logging.error("caught exception: {}, defined in {}. we are in
{}".format(
e.__class__.__name__,
inspect.getfile(e.__class__),
os.getcwd()
))
logging.error("processed exception: {}, defined in {}.".format(
HttpError.__name__,
inspect.getfile(HttpError)
))
logging.error('e is an HttpError? {}'.format(isinstance(e,
HttpError)))
```

This code generates instead the messages:
```
ERROR 47.135[bigquery.py.create_table:362] caught exception: HttpError,
defined in server/libs/googleapiclient/errors.pyc. we are in
/Users/nilleb/dev/gae-sample-project/app
ERROR 47.135[bigquery.py.create_table:366] processed exception: HttpError,
defined in
/Users/nilleb/dev/gae-sample-project/app/server/libs/googleapiclient/errors.pyc.
ERROR 47.136[bigquery.py.create_table:368] e is an HttpError? False
```

I haven't joined the paths in the messages above, but they are identical if
I do that manually:

```
/Users/nilleb/dev/gae-sample-project/app/server/libs/googleapiclient/errors.pyc
/Users/nilleb/dev/gae-sample-project/app/server/libs/googleapiclient/errors.pyc
```

Any ideas about how to diagnostic what's going wrong?

Thanks in advance,
nilleb
-- 
https://mail.python.org/mailman/listinfo/python-list


Python-2.3.4 on OSF1 V4.0?

2008-08-28 Thread Ivo Raisr
Hi Edmond and any interested reader,
I've successfully patched _socket extension of python 2.5.1 to build
on OSF1 V4.0 with gcc 4.1.2.
The following construct is put right after #include "Python.h" and
#include "structmember.h":
#define _POSIX_PII_SOCKET
#define _LIBC_POLLUTION_H_

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


Re: python without while and other "explosive" statements

2008-05-12 Thread ivo talvet
thanks for the tips, pam limits and http://codepad.org/ are both
interesting tracks.

Ivo

2008/5/12 Matt Nordhoff <[EMAIL PROTECTED]>:
>
> ivo talvet wrote:
>  > Hello,
>  >
>  > Is it possible to have a python which not handle the execution of
>  > "while", "for", and other loop statements ? I would like to allow
>  > remote execution of python on a public irc channel, so i'm looking for
>  > techniques which would do so people won't be able to crash my computer
>  > (while 1: os.fork(1)), or at least won't won't freeze my python in a
>  > infinite loop, make it unresponsive. Is there a compiling option (or
>  > better, something i can get with apt-get cos i think compiling myself
>  > and handle all the metastuff myself is somehow dirty) for have a
>  > "secure python" (you can guess what i mean by "secure" in my case) or
>  > must i touch myself the source disable some code lines ? If last
>  > solution, which modifications in which files should i do ? (sorry for
>  > my bad english)
>  >
>  > Thanks.
>  >
>  > Ivo
>
>  <http://codepad.org/> is a pastebin-like website that lets people upload
>  code in a dozen different languages, and it runs it. They have info up
>  about how it's secure at <http://codepad.org/about>.
>
>  I'm pretty sure there's another similar website that's specific to
>  Python, but I can't remember it. Anyway, it was similar, using virtual
>  machines, a firewall, and killing stuff that ran for longer than 20
>  seconds, IIRC.
>
>  (Thanks for the link to codepad, habnabit.)
>  --
>
--
http://mail.python.org/mailman/listinfo/python-list


python without while and other "explosive" statements

2008-05-11 Thread ivo talvet
Hello,

Is it possible to have a python which not handle the execution of
"while", "for", and other loop statements ? I would like to allow
remote execution of python on a public irc channel, so i'm looking for
techniques which would do so people won't be able to crash my computer
(while 1: os.fork(1)), or at least won't won't freeze my python in a
infinite loop, make it unresponsive. Is there a compiling option (or
better, something i can get with apt-get cos i think compiling myself
and handle all the metastuff myself is somehow dirty) for have a
"secure python" (you can guess what i mean by "secure" in my case) or
must i touch myself the source disable some code lines ? If last
solution, which modifications in which files should i do ? (sorry for
my bad english)

Thanks.

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


Re: interested????

2008-02-05 Thread Ivo
no
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: polling for output from a subprocess module

2008-02-05 Thread Ivo
Thomas Bellman wrote:
> [EMAIL PROTECTED] wrote:
> 
>>   try:
>> test = Popen(test_path,
>>   stdout=PIPE,
>>   stderr=PIPE,
>>   close_fds=True,
>>   env=test_environ)
> 
>> while test.poll() == None:
>> ready = select.select([test.stderr], [], [])
> 
>> if test.stderr in ready[0]:
>> t_stderr_new = test.stderr.readlines()
>> if t_stderr_new != []:
>> print "STDERR:", "\n".join(t_stderr_new)
>> t_stderr.extend(t_stderr_new)
> [...]
>> The problem is, that it seems that all the output from the subprocess
>> seems to be coming at once. Do I need to take a different approach?
> 
> The readlines() method will read until it reaches end of file (or
> an error occurs), not just what is available at the moment.  You
> can see that for your self by running:
> 
> $ python -c 'import sys; print sys.stdin.readlines()'
> 
> The call to sys.stdin.readlines() will not return until you press
> Ctrl-D (or, I think, Ctrl-Z if you are using MS-Windows).
> 
> However, the os.read() function will only read what is currently
> available.  Note, though, that os.read() does not do line-based
> I/O, so depending on the timing you can get incomplete lines, or
> multiple lines in one read.
> 
> 
be carefull that you specify how much you want to read at a time, 
otherwise it cat be that you keep on reading.

Specify read(1024) or somesuch.

In case of my PPCEncoder I recompiled the mencoder subprocess to deliver 
me lines that end with \n.

If anyone can tell me how to read a continues stream than I am really 
interested.

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


Re: Simple HTML template engine?

2007-10-15 Thread Ivo
Ciprian Dorin Craciun wrote:
> Have you tried CherryPy? http://www.cherrypy.org/
> 
> It's not a template engine, but a simple web server engine, and
> you could code your conditionals and loops directly in Python... When
> I have tried it, it looked very nice and easy.
> 
> Ciprian.
> 
> 
> On 10/15/07, allen.fowler <[EMAIL PROTECTED]> wrote:
>> Hello,
>>
>> Can anyone recommend a simple python template engine for generating
>> HTML that relies only on the Pyhon Core modules?
>>
>> No need for caching, template compilation, etc.
>>
>> Speed is not a major issue.
>>
>> I just need looping and conditionals. Template inheritance would be a
>> bonus.
>>
>> I've seen Genshi and Cheetah, but they seem way too complex.
>>
>> Any ideas?
>>
>> I'm sure I could build something myself, but I'm sure this has already
>> been done quite a few times.  Why re-invent the wheel, right?
>>
>>
>> Thank you,
>> Allen

I concur completely!
My site http://IvoNet.nl is completely written in python and based on a 
very early release of cherrypy.

gr,
Ivo.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Resolving windows shortcut to url

2007-09-21 Thread Ivo
Ivo wrote:
> Richard Townsend wrote:
>> If I have a windows shortcut to a URL, is there a way to get the URL
>> in a Python app?
>>
>> I found some code that uses pythoncom to resolve shortcuts to local
>> files, but I haven't found any examples for URLs.
>>
>> The PyWin32 help mentions the PyIUniformResourceLocator Object, but I
>> couldn't find an example of how to use it.
>>
> do you mean a *.lnk file or a *.url file?

for a link (*.lnk) file:


from win32com.shell import shell
import pythoncom
import os, sys

class PyShortcut(object):
 def __init__(self):
 self._base = pythoncom.CoCreateInstance(shell.CLSID_ShellLink,
 None,
 
pythoncom.CLSCTX_INPROC_SERVER,
 shell.IID_IShellLink)

 def load(self, filename):
 
self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename)

 def save(self, filename):
 
self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(filename, 0)

 def __getattr__(self, name):
 if name != "_base":
 return getattr(self._base, name)


if __name__=="__main__":
 lnk = PyShortcut()
 lnk.load("path to your shortcut file including the .lnk extention 
even if you don't see it in windows")
 print "Location:", lnk.GetPath(shell.SLGP_RAWPATH)[0]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Resolving windows shortcut to url

2007-09-21 Thread Ivo
Ivo wrote:
> Richard Townsend wrote:
>> If I have a windows shortcut to a URL, is there a way to get the URL
>> in a Python app?
>>
>> I found some code that uses pythoncom to resolve shortcuts to local
>> files, but I haven't found any examples for URLs.
>>
>> The PyWin32 help mentions the PyIUniformResourceLocator Object, but I
>> couldn't find an example of how to use it.
>>
> do you mean a *.lnk file or a *.url file?

if an *.url file just open it as a properties file (ConfigParser) 
because it looks something like:


[InternetShortcut]
URL=http://ivonet.nl/
IDList=
IconFile=http://ivonet.nl/favicon.ico
IconIndex=1
[{000214A0---C000-0046}]
Prop3=19,2

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


Re: Resolving windows shortcut to url

2007-09-21 Thread Ivo
Richard Townsend wrote:
> If I have a windows shortcut to a URL, is there a way to get the URL
> in a Python app?
> 
> I found some code that uses pythoncom to resolve shortcuts to local
> files, but I haven't found any examples for URLs.
> 
> The PyWin32 help mentions the PyIUniformResourceLocator Object, but I
> couldn't find an example of how to use it.
> 
do you mean a *.lnk file or a *.url file?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: elementtree question

2007-09-21 Thread Ivo
Tim Arnold wrote:
> Hi, I'm using elementtree and elementtidy to work with some HTML files. For 
> some of these files I need to enclose the body content in a new div tag, 
> like this:
> 
>   
>original contents...
>   
> 
> 
> I figure there must be a way to do it by creating a 'div' SubElement to the 
> 'body' tag and somehow copying the rest of the tree under that SubElement, 
> but it's beyond my comprehension.
> 
> How can I accomplish this?
> (I know I could put the class on the body tag itself, but that won't satisfy 
> the powers-that-be).
> 
> thanks,
> --Tim Arnold
> 
> 

You could also try something like this:

from sgmllib import SGMLParser
class IParse(SGMLParser):
 def __init__(self, verbose=0):
 SGMLParser.__init__(self, verbose)
 self.data = ""
 def _attr_to_str(self, attrs):
 return ' '.join(['%s="%s"' % a for a in attrs])

 def start_body(self, attrs):
 self.data += "" % self._attr_to_str(attrs)
 print "remapping"
 self.data += ''
 def end_body(self):
 self.data += "" # end remapping
 self.data += ""
 def handle_data(self, data):
 self.data += data
 def unknown_starttag(self, tag, attrs):
 self.data+="<%s %s>" % (tag,  self._attr_to_str(attrs),)
 def unknown_endtag(self, tag):
 self.data += "" % tag


if __name__=="__main__":
 i = IParse()
 i.feed('''

 
 original
 italic
 contents...
 
''');

 print i.data
 i.close()


just look at the code from sgmllib (standard lib) and it is very easy to 
make a parser. for some much needed refactoring

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


Re: Remote Command a Python Script

2007-09-21 Thread Ivo
Ulysse wrote:
> Hello,
> 
> I've installed Python 2.5 on my WRT54G Linksys Router. On this router
> a script is executed. This script write a little Pickle database in
> the router memory.
> 
> I would like to write another Python script which will be able to :
> 
> 1. Stop and start the remote script from my Windows Computer. At
> present I use Putty to connect to the router by the SSL, then I
> manually kill the python process.
> 
> 2. Retrieve the little database located in router memory and backup it
> on my Window PC. At present I use WinSCP (like FTP) to get the pickle
> file.
> 
> Can you help me with that (modules to use, useful code snippets)
> 
> Thank a lot,
> 
> Maxime
> 
or SPyRO
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Regex Question

2007-09-21 Thread Ivo
crybaby wrote:
> On Sep 20, 4:12 pm, Tobiah <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>>> I need to extract the number on each >> i.e 49.950 from the following:
>>>  49.950 
>>> The actual number between:  49.950  can be any number of
>>> digits before decimal and after decimal.
>>>  ##. 
>>> How can I just extract the real/integer number using regex?
>> '[0-9]*\.[0-9]*'
>>
>> --
>> Posted via a free Usenet account fromhttp://www.teranews.com
> 
> I am trying to use BeautifulSoup:
> 
> soup = BeautifulSoup(page)
> 
> td_tags = soup.findAll('td')
> i=0
> for td in td_tags:
> i = i+1
> print "td: ", td
> # re.search('[0-9]*\.[0-9]*', td)
> price = re.compile('[0-9]*\.[0-9]*').search(td)
> 
> I am getting an error:
> 
>price= re.compile('[0-9]*\.[0-9]*').search(td)
> TypeError: expected string or buffer
> 
> Does beautiful soup returns array of objects? If so, how do I pass
> "td" instance as string to re.search?  What is the different between
> re.search vs re.compile().search?
> 

I don't know anything about BeautifulSoup, but to the other questions:

var=re.compile(regexpr) compiles the expression and after that you can 
use var as the reference to that compiled expression (costs less)

re.search(expr, string) compiles and searches every time. This can 
potentially be more expensive in calculating power. especially if you 
have to use the expression a lot of times.

The way you use it it doesn't matter.

do:
pattern = re.compile('[0-9]*\.[0-9]*')
result = pattern.findall(your tekst here)

Now you can reuse pattern.

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


Re: Python Database Apps

2007-09-11 Thread Ivo
[EMAIL PROTECTED] wrote:
> Kindof a poll, kindof curiosity...
> 
> What is your favorite python - database combination?  I'm looking to
> make an app that has a local DB and a server side DB.  I'm looking at
> python and sqlite local side and sql server side.
> 
> Any suggestions
> 
> Darien
> 
If you like to make a kind of stand alone app with a database, SQLite a 
good choice. It is easy to embed into your app. If you keep to ANSI SQL 
there should be no trouble changing databases at a later date.
I use SQLite for my WebSite http://IvoNet.nl and it performs great.
The whole database is less than 1Mb including the SQLite module for 
python. No 50Mb install needed if you just want a simple database.
It makes my website very portable and easy to install.

MySQL works great to. I have used it a lot and it is very available. 
Just about every provider can provide you one.

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


Re: Relative paths in mod_python

2006-03-20 Thread Ivo van der Sangen
On 2006-03-19, Bruno Desthuilliers <[EMAIL PROTECTED]> 
wrote:
> Ivo van der Sangen a écrit :
>> I was wondering if I could use relative paths in a mod_python script. At
>> the moment I am defining a constant string
>> "/path/to/dir/where/script/resides". The problem with this is that when
>> I move the script including files I use to get metadata I have to change
>> this variable. The same problem occurs when I distribute the script; the
>> person using it will first have to modify it, which is not what I want. Is
>> it possible that a mod_python script has as current working directory
>> the directory where the script resides? At the moment os.getcwd()
>> returns '/'.
>
> You could set this constant in the apache conf as a PythonOption. And/Or 
> you could post this question to mod_python's mailing list !-)

I wasn't aware of the mod_python list. The next time I will post my
question there, but I don't think I will get a better answer there; the
solutions given here so far are fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Relative paths in mod_python

2006-03-19 Thread Ivo van der Sangen
I was wondering if I could use relative paths in a mod_python script. At
the moment I am defining a constant string
"/path/to/dir/where/script/resides". The problem with this is that when
I move the script including files I use to get metadata I have to change
this variable. The same problem occurs when I distribute the script; the
person using it will first have to modify it, which is not what I want. Is
it possible that a mod_python script has as current working directory
the directory where the script resides? At the moment os.getcwd()
returns '/'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess.Popen() redirecting to TKinter or WXPython textwidget???

2005-01-26 Thread Ivo Woltring

<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Ivo, my initial thought would be, you need to know how much text you
> will get back from popen.  My Python reference has the following
> example:
>
> import os
> dir = os.popen('ls -al', 'r')
> while (1):
> line = dir.readline()
> if line:
> print line,
> else:
> break
>
> that example shows how to capture the process output in a file-type
> object, then bring it into a string with readline().
>
>[ snip ]
> cheers
> S
>


Thanx for trying Stewart,
 but that is not what I need
The output of mencoder is not readable with readlines (i tried it) because
after the initial informational lines You don't get lines anymore (you get a
linefeed but no newline)
The prints are all on the same line (like a status line)
something like
Pos:   3,1s 96f ( 0%)  42fps Trem:   0min   0mb  A-V:0,038 [171:63]

which is coninually updated while the process runs...

> in your app, you could create a Tkinter stringVar, say myOutput, for
> the process output. In your Tkinter widget, you could then set a
> textvariable=myOutput. also use the wait_variable and watch options

How does this work? wait?? anyone?

> (hope I recall these correctly, don't have my Tkinter ref. at hand) to
> detect when there's been a change to the contents of the StringVar and
> update the contents of the label.
> Hope this helps, if not, write back.

I really like to know how I can catch the output of a subproces.Popen()
command and redirect it to something else (like a textwidget )
and I really like to use the subprocess module (standard in v2.4) to get to
know it.
Another reason to use the subprocess module is I can stop the process
because I know the handle of the thread. The subprocess module knows all
this.

cheerz,
Ivo.


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


subprocess.Popen() redirecting to TKinter or WXPython textwidget???

2005-01-26 Thread Ivo Woltring
Hi Pythoneers,

I am trying to make my own gui for mencoder.exe (windows port of the
terrific linux mencoder/mplayer) to convert divx to Pocket_PC size.
My current app creates a batch script to run the mencoder with the needed
params, but now I want to integrate mencoder as a subprocess in my app.

What already works:
the starting of the subprocess.Popen
and the subsequent killing of the process if I want it to.
My gui does not freeze up as it did in my first tries.

What I want to know (what does not yet work ;-)):
- Redirecting the output of the subprocess to a textwidget in my GUI

Any example or help is much appreceated.

I tried the subprocess.PIPE but I think I don't really understand how it is
suppost to work
The redirecting to a file does work but this not my objective...
So I'm stuck. HELP
The started processes are long and I want to be able to show some kind of
progress-status.

Thanx,
Ivo Woltring


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


Reading raw data from disc

2004-12-13 Thread Ivo Woltring
Dear Pythoneers,

Is it possible to read e.g. the first 3 sectors of a disc without opening a
file or somesuch?
I want to bitwise read a cd-rom or other media without consulting a table of
contents. Just start at track 0 and go on for x bytes. Is it possible with
python and if so, please help me in the right direction

thankx
Ivo.


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


Re: MP3 - VBR - Frame length in time

2004-12-12 Thread Ivo Woltring

"Florian Schulze" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Sat, 11 Dec 2004 20:32:30 +0100, Ivo Woltring <[EMAIL PROTECTED]>
> wrote:
>
> > mmpython will help but not always.
> > Lets put it this way. I will ALWAYS read through the whole file. In that
> > order I don't mind evaluating each frame. The thing I don't seem to be
> > able
> > to find is the timelength-constants for frames for the different mp3
> > versions, bitrates and layers. Can anybody help me?
>
>  From http://www.oreilly.com/catalog/mp3/chapter/ch02.html#71109
> "In addition, the number of samples stored in an MP3 frame is constant, at
> 1,152 samples per frame."
>
>
> So you only need the samplerate for each frame to calculate the duration
> of that frame.
>
> 1152 samples / 44100 samples per second ~ 0.026 seconds
>
> I don't exactly know whether you need to include mono/stereo into the
> calculation, you would have to test that out.
>
> Regards,
> Florian Schulze
>
thanks!
will try this out
Greetz,
Ivo.


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


Re: MP3 - VBR - Frame length in time

2004-12-11 Thread Ivo Woltring

"JanC" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Dmitry Borisov schreef:
>
> > It has something to deal with the VBR tags( XING header ).
>
> *If* there is a VBR tag (it's a custom extension) and *if* that VBR tag
> contains a correct value.
>
>
> -- 
> JanC
>
> "Be strict when sending and tolerant when receiving."
> RFC 1958 - Architectural Principles of the Internet - section 3.9

mmpython will help but not always.
Lets put it this way. I will ALWAYS read through the whole file. In that
order I don't mind evaluating each frame. The thing I don't seem to be able
to find is the timelength-constants for frames for the different mp3
versions, bitrates and layers. Can anybody help me?

Thnaks,
Ivo


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


MP3 - VBR - Frame length in time

2004-12-08 Thread Ivo Woltring
Dear Pythoneers,

I have this problem with the time calculations of an VBR (variable bit rate)
encoded MP3.
I want to make a daisy writer for blind people. To do this I have to know
exactly what the length in time of an mp3 is. With CBR encoded files I have
no real problems (at least with version 1 and 2), but with VBR encoded I get
into trouble.
I noticed that players like WinAMP and Windows Media player have this
problem too.
I don't mind to have to read the whole mp3 to calculate, because performance
is not a real issue with my app.

Can anyone help me? I am really interested in technical information on VBR
and MP3.
Can anybody tell me the length in time of the different bitrates in all the
versions of mp3 and all the layers.

Tooling or links also really welcome. My own googling has helped me some but
on the subject of VBR I get stuck.

Thanks a lot,
Ivo.


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