extract substring by regex from a text file

2010-04-15 Thread Alessio
Hi,

I'm facing the problem in the subject:
- I have a text file that I need to parse for producing a specifical
string (Json like) extracting some information (substring) in it;
- I created regural expressions capable to locate these substrings in
my txt file;

now I don't know how to continue. What is the best way to locate some
string in a file and output them (with print command or in another
file)?

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


Re: extract substring by regex from a text file

2010-04-17 Thread Alessio
On Apr 15, 3:25 pm, Neil Cerutti  wrote:
> On 2010-04-15, Alessio  wrote:
>
> > Hi,
>
> > I'm facing the problem in the subject:
> > - I have a text file that I need to parse for producing a specifical
Thank you, I forgot to say that I already solved.
I used readlines() to read my text file, then with a for cicle I
extract line by line the substrings I need by regular expressions
(re.findall())

ciao


> > string (Json like) extracting some information (substring) in it;
> > - I created regural expressions capable to locate these substrings in
> > my txt file;
>
> > now I don't know how to continue. What is the best way to locate some
> > string in a file and output them (with print command or in another
> > file)?
>
> grep
>
> Or: show your work.
>
> --
> Neil Cerutti

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


Re: extract substring by regex from a text file

2010-04-17 Thread Alessio
On Apr 17, 11:05 am, Peter Otten <__pete...@web.de> wrote:
>
> Just in case you didn't know:
>
>     for line in instream:
>         ...
>
> looks better, uses less memory, and may be a tad faster than
>
>     for line in instream.readlines():
>         ...
>
> Peter

Thanks for your suggestions, they are welcome... I'm at the beginning
with python.
I just changed my script to parse the file without readlines()

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


How to distribute a Python app together with its dependencies?

2008-11-30 Thread Alessio Pace
Hi,

I have to distribute a Python application which relies on an external
library, and I'm not very fluent in this kind of stuff with Python (I
come from the Java world where I would have used the Maven build tool
to create an "assembly with dependencies" of all it is needed to run
the app), so I was wondering if someone here could give me some
suggestions :-)

The external library is generally not present on the machines where I
have to distribute my app, and the set of machines on which I have to
distribute this application is not known a priori (it is just known
they are Unix systems). In fact by means of SSH I will have to copy
(and install) the app+library and make it runnable onto the specified
destination(s).

My question is: how would you do that?  At the moment my current
solution is to make a tarball of the sources of my app + the
"distutils" archive of the external library, copy all into the target
machine, decompress and install via distutils(*) the external library,
setup some PYTHONPATH stuff on the destination machine, and finally be
able to launch the application.

(*) specifying a prefix into the user home, as I'm not root there


So in the end I was wondering if there is a more elegant way of doing
this because, as I said before, I'm not very experienced in these kind
of tasks in Python.

Thanks in advance for any suggestion or comment.

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


Re: How to distribute a Python app together with its dependencies?

2008-11-30 Thread Alessio Pace
On 1 Dic, 05:23, Lev Elbert <[EMAIL PROTECTED]> wrote:
> If Python for Windows you can use Py2Exe package. It works very well
> in simple cases and requires a few tweaks to make it recognize some
> dependencies.

As I was saying above, the destination machines are all Unix.

Thank you anyway for your suggestion, I'll keep it in mind if I can to
deploy on Windows too.

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


Re: How to distribute a Python app together with its dependencies?

2008-12-01 Thread Alessio Pace
On 1 Dic, 10:37, BlueBird <[EMAIL PROTECTED]> wrote:
> Alessio Pace wrote:
> > Hi,
>
> > I have to distribute a Python application which relies on an external
> > library, and I'm not very fluent in this kind of stuff with Python (I
> > come from the Java world where I would have used the Maven build tool
> > to create an "assembly with dependencies" of all it is needed to run
> > the app), so I was wondering if someone here could give me some
> > suggestions :-)
>
> > The external library is generally not present on the machines where I
> > have to distribute my app, and the set of machines on which I have to
> > distribute this application is not known a priori (it is just known
> > they are Unix systems). In fact by means of SSH I will have to copy
> > (and install) the app+library and make it runnable onto the specified
> > destination(s).
>
> I have never used it myself, but bbfreeze claims to create packaged
> versions of an application, for windows and Unix :
>
> http://pypi.python.org/pypi/bbfreeze/0.95.2
>

Thank you. What's the difference with "Freeze" shipped with Python, or
with PyInstaller ? Do you have experiences with any of them?


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


Re: How to distribute a Python app together with its dependencies?

2008-12-01 Thread Alessio Pace
On 1 Dic, 10:37, BlueBird <[EMAIL PROTECTED]> wrote:
> Alessio Pace wrote:
> > Hi,
>
> > I have to distribute a Python application which relies on an external
> > library, and I'm not very fluent in this kind of stuff with Python (I
> > come from the Java world where I would have used the Maven build tool
> > to create an "assembly with dependencies" of all it is needed to run
> > the app), so I was wondering if someone here could give me some
> > suggestions :-)
>
> > The external library is generally not present on the machines where I
> > have to distribute my app, and the set of machines on which I have to
> > distribute this application is not known a priori (it is just known
> > they are Unix systems). In fact by means of SSH I will have to copy
> > (and install) the app+library and make it runnable onto the specified
> > destination(s).
>
> I have never used it myself, but bbfreeze claims to create packaged
> versions of an application, for windows and Unix :
>
> http://pypi.python.org/pypi/bbfreeze/0.95.2
>

Thank you. What's the difference with "Freeze" shipped with Python, or
with PyInstaller ? Do you have experiences with any of them?


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


Re: How to distribute a Python app together with its dependencies?

2008-12-01 Thread Alessio Pace
On 1 Dic, 15:21, Mike Driscoll <[EMAIL PROTECTED]> wrote:
> On Nov 30, 6:22 am, Alessio Pace <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > I have to distribute a Python application which relies on an external
> > library, and I'm not very fluent in this kind of stuff with Python (I
> > come from the Java world where I would have used the Maven build tool
> > to create an "assembly with dependencies" of all it is needed to run
> > the app), so I was wondering if someone here could give me some
> > suggestions :-)
>
> > The external library is generally not present on the machines where I
> > have to distribute my app, and the set of machines on which I have to
> > distribute this application is not known a priori (it is just known
> > they are Unix systems). In fact by means of SSH I will have to copy
> > (and install) the app+library and make it runnable onto the specified
> > destination(s).
>
> > My question is: how would you do that?  At the moment my current
> > solution is to make a tarball of the sources of my app + the
> > "distutils" archive of the external library, copy all into the target
> > machine, decompress and install via distutils(*) the external library,
> > setup some PYTHONPATH stuff on the destination machine, and finally be
> > able to launch the application.
>
> > (*) specifying a prefix into the user home, as I'm not root there
>
> > So in the end I was wondering if there is a more elegant way of doing
> > this because, as I said before, I'm not very experienced in these kind
> > of tasks in Python.
>
> > Thanks in advance for any suggestion or comment.
>
> > Alessio Pace.
>
> I recommend GUI2Exe, a nice wrapper to py2exe, py2app, PyInstaller,
> cx_Freeze and bbFreeze:
>
> http://code.google.com/p/gui2exe/
>
> I've only used the py2exe portion of the program, but it works great
> and the developers behind the project are very responsive and helpful.
>
> Mike

Hi all and thanks for the replies.  Apparenlty I managed to make the
standalone application with bbfreeze (used directly), I still have to
tune a little bit how it can pack in it also classes which are loaded
dynamically, and which from a static examination of the code are not
found then...

I'll try to give a look at GUI2Exe also, thank you for the suggestion.

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


Portable (Linux/Mac/Win) way to get network interfaces names and their addresses?

2009-01-06 Thread Alessio Pace
Hi,

I'm wondering how could I get, possibly in a pure Python solution, the
list of network addresses on a machine and the IP address of each of
them.

In fact I came across recently on two solutions, one that is pure
Python but that works only on Linux:

#
def all_interfaces():
max_possible = 128  # arbitrary. raise if needed.
bytes = max_possible * 32
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
names = array.array('B', '\0' * bytes)
outbytes = struct.unpack('iL', fcntl.ioctl(
s.fileno(),
0x8912,  # SIOCGIFCONF
struct.pack('iL', bytes, names.buffer_info()[0])
))[0]
namestr = names.tostring()
return [namestr[i:i+32].split('\0', 1)[0] for i in range(0,
outbytes, 32)]

def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915,  # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
###

and one other instead that is in the "netifaces" package (=>
http://alastairs-place.net/netifaces/) which is written in C.


Thanks in advance for any suggestion.
--
Alessio Pace.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Land Of Lisp is out

2010-10-29 Thread Alessio Stalla
On 28 Ott, 10:42, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> sthueb...@googlemail.com (Stefan Hübner) writes:
> >> Would it be right to say that the only Lisp still in common use is the 
> >> Elisp
> >> built into Emacs?
>
> > Clojure (http://clojure.org) is a Lisp on the JVM. It's gaining more and
> > more traction.
>
> There are actually 2 REAL Lisp on the JVM:
>
> - abclhttp://common-lisp.net/project/armedbear/and
>
> - CLforJavahttp://www.clforjava.org

Well, there are a few Scheme implementations too. Kawa is "famous" for
having been used by Google as the basis for their App Inventor for
Android. And I wouldn't define Clojure a "fake" Lisp. It has some
aspects I don't like, but it is definitely in the Lisp family.
Actually CLforJava as far as I know is missing crucial features (e.g.
CLOS) and in some aspects is more tied to Java than Clojure.
-- 
http://mail.python.org/mailman/listinfo/python-list