Hi,
I have a script (see below) that I want to terminate after X seconds.
The main loop of the program is waiting for user input.
The program enters the main loop and I try to shut down the program
after X seconds from a thread but I can't figure out how to do it. The
program should also do some
You need a flag to indicate that a particular invocation is the
dummy one (background). So use that same flag either to suppress
starting the thread, or to avoid the unwanted raw_input.
Alternatively, rethink the need to preload at boot time. Any
caching the OS does is likely to only
Hi,
I have a simple command-line radio player and I want to extract song
titles from the output of mplayer.
Example:
$ mplayer http://relay2.slayradio.org:8000/
It produces a streamed output of this form:
MPlayer2 UNKNOWN (C) 2000-2012 MPlayer Team
mplayer: could not connect to socket
Python. (Or s/guess/hop/ if you prefer!) There are many ways this
could be done; what have you tried, what partly worked, what did
something unexpected?
Hi,
I managed to solve the problem. In the man of mplayer I found how to
quit after X seconds: -endpos X. See my solution below.
Best,
Hi,
The first line in my scripts looks like this:
#!/usr/bin/env python
I would like to use unbuffered output in a script, which can be done
with the -u option, thus I tried this:
#!/usr/bin/env python -u
But if I want to run it from the command line ($ ./unbuffered.py), I
get this error:
Hi,
I'm playing with Flask and I would like to try it in production
environment too. I managed to bring Flask together with uwsgi and
nginx. My Flask application is available at the address localhost:81 .
I would like to add several applications and I want them to be
available under different
Hi Ned,
Could you please post here your AppArmor profile for restricted Python scripts?
Thanks,
Laszlo
On Sat, Sep 21, 2013 at 12:46 AM, Ned Batchelder n...@nedbatchelder.com wrote:
On 9/20/13 6:26 PM, Jabba Laci wrote:
I just found Docker ( http://docs.docker.io/en/latest/faq/ ). It seems
Hi,
In our school I have an introductory Python course. I have collected a
large list of exercises for the students and I would like them to be
able to test their solutions with an online judge (
http://en.wikipedia.org/wiki/Online_judge ). At the moment I have a
very simple web application that
Let's take this simple exercise:
Write a function that receives a list and decides whether the list is
sorted or not.
Here the output of the function is either True or False, so I cannot
test it with my current method.
Laszlo
On Fri, Sep 20, 2013 at 7:57 PM, Aseem Bansal asmbans...@gmail.com
That last seems to me to be the biggie. Several times in the past few
years, people in this mailing list have tried to build a safe sandbox.
And each one was a big failure, for a hacker of sufficient interest.
Some of them were spectacular failures.
If you have to be safe from your user,
I just found Docker ( http://docs.docker.io/en/latest/faq/ ). It seems
sandboxing could be done with this easily.
Laszlo
On Fri, Sep 20, 2013 at 10:08 PM, John Gordon gor...@panix.com wrote:
In mailman.195.1379698177.18130.python-l...@python.org Jabba Laci
jabba.l...@gmail.com writes
Hi,
How can you detect if a key is duplicated in a JSON file? Example:
{
something: [...],
...
something: [...]
}
I have a growing JSON file that I edit manually and it might happen
that I repeat a key. If this happens, I would like to get notified.
Currently the value of the second
The real answer here is that JSON is probably not the best choice for
large files that get hand-edited. For data that you intend to hand-edit
a lot, YAML might be a better choice.
Currently the value of the second key silently overwrites the value of
the first.
Thanks but how would it be
Hi,
I wonder if there is a nice way to extract a whole HTML table and have the
result in a nice structured format. What I want is to have the lifetime
table at the bottom of this page:
http://en.wikipedia.org/wiki/List_of_Ubuntu_releases (then figure out with
a script until when my Ubuntu release
.
Best,
Laszlo
On Wed, Apr 10, 2013 at 8:11 PM, Arnaud Delobelle arno...@gmail.com wrote:
On 10 April 2013 09:44, Jabba Laci jabba.l...@gmail.com wrote:
Hi,
I wonder if there is a nice way to extract a whole HTML table and have
the
result in a nice structured format. What I want
Hi,
As a university project, I would like to work on an automated
converter that transforms a Python source code to C++ or Java (not yet
decided but I would vote on Java since it seems less complicated).
Do you know if it's already done? What other similar projects are you aware of?
And most
Hi,
Thanks for the answers. I like the context manager idea but setting
the sys.stdout back to the original value doesn't work.
Example:
class Unbuff(object):
def __init__(self):
self.stdout_bak = sys.stdout
def __enter__(self):
sys.stdout.flush()
sys.stdout =
#
return get_fingerprint(md5=True)[-length:]
On Tue, Jan 29, 2013 at 2:43 PM, Andrew Berg bahamutzero8...@gmail.com wrote:
On 2013.01.29 07:18, Jabba Laci wrote:
Hi,
I have a script that I want to run in different environments: on
Linux, on Windows, on my home machine, at my workplace
in the
future.
Best,
Laszlo
On Tue, Dec 11, 2012 at 1:16 AM, Chris Angelico ros...@gmail.com wrote:
On Tue, Dec 11, 2012 at 11:05 AM, Jabba Laci jabba.l...@gmail.com wrote:
Hi,
If this is for use on somebody else's system, *please don't*. My
This is for me. I have a simple GUI that produces
Hi,
With the webbrowser module you can open a URL in a new tab. But how
could I tell Firefox from Python to open a URL in the _current_ tab?
Thanks,
Laszlo
--
http://mail.python.org/mailman/listinfo/python-list
sst.actions import *
go_to('http://www.ubuntu.com/')
2012/12/10 Jabba Laci jabba.l...@gmail.com:
Hi,
With the webbrowser module you can open a URL in a new tab. But how
could I tell Firefox from Python to open a URL in the _current_ tab?
Thanks,
Laszlo
--
http://mail.python.org/mailman
Hi,
If this is for use on somebody else's system, *please don't*. My
This is for me. I have a simple GUI that produces some URL that I want
to open in the current tab. Since I want to verify several URLs, I
don't want to open dozens of new tabs.
Here is my working solution. It requires the
Hi,
I have a strange problem. I've used PyDev for a long time and a few
days ago I wanted to try PyCharm. When I wanted to create a new
project in PyCharm, it asked me to select the interpreter. There was a
possibility to upgrade packages so I selected all and pressed the
upgrade button. For the
6, 2012 at 7:30 PM, Jabba Laci jabba.l...@gmail.com wrote:
Hi,
I have a strange problem. I've used PyDev for a long time and a few
days ago I wanted to try PyCharm. When I wanted to create a new
project in PyCharm, it asked me to select the interpreter. There was a
possibility to upgrade
Hi,
I'm trying to use fabric to run a command on another Linux machine.
When I call fab remote_info (using the example from its
documentation), this is what I get:
local$ fab remote_info
[remote] Executing task 'remote_info'
[remote] run: uname -a
[remote] out: remote@path$
That is, it logs in
Hi,
I have an installer script that contains lots of little functions. It
has an interactive menu and the corresponding function is called. Over
time it grew long and when I want to add a new function, I should give
a unique name to that function. However, Python allows the
redefinition of
For example:
def install_java():
pass
def install_tomcat():
pass
Thanks for the answers. I decided to use numbers in the name of the
functions to facilitate function calls. Now if you have this menu
option for instance:
(5) install mc
You can type just 5 as user input and step_5()
Hehe, I just asked this question a few days ago but I didn't become
much cleverer:
http://www.gossamer-threads.com/lists/python/python/985701
Best,
Laszlo
On Thu, May 10, 2012 at 2:14 PM, Jabba Laci jabba.l...@gmail.com wrote:
Hi,
I would like to do some parallel programming with Python
Hi,
I would like to do some parallel programming with Python but I don't
know how to start. There are several ways to go but I don't know what
the differences are between them: threads, multiprocessing, gevent,
etc.
I want to use a single machine with several cores. I want to solve
problems like
...@davea.name wrote:
On 05/10/2012 08:14 AM, Jabba Laci wrote:
Hi,
I would like to do some parallel programming with Python but I don't
know how to start. There are several ways to go but I don't know what
the differences are between them: threads, multiprocessing, gevent,
etc.
I want to use
Hi,
I want to figure out where a host is located, in which country. There
are sites that look up this information (e.g.
http://geoip.flagfox.net/). Before writing a scraper, I would like to
ask if you know a python API for this task.
Thanks,
Laszlo
--
I've found a web service for the task:
http://www.geoplugin.com/webservices . It can produce JSON output too.
Laszlo
On Tue, May 1, 2012 at 09:35, Jabba Laci jabba.l...@gmail.com wrote:
Hi,
I want to figure out where a host is located, in which country. There
are sites that look up
Hi,
Try this:
import sys
for i in range (1, 5+1):
for j in range (i):
sys.stdout.write(str(i))
print
print adds a newline character
print hi, notice the comma, it won't add newline, however
it adds a space
With sys.stdout.write you can print the way you want, it won't add any
Hi,
I'm working with some sorting algorithms and I want to compare their
efficiency. One test fills a list with one million random integers,
which serves as input for the algorithms. However, if this list is
different each time I run the tests, the tests wouldn't be fair. At
the moment the
Hi,
I'd like to work with the digits of pi. I would need high precision,
like 100,000 digits or even more. At the moment I download the
necessary data from the web
(http://newton.ex.ac.uk/research/qsystems/collabs/pi/) and parse it.
I just wonder: is there a more elegant way? I found a Perl
Hi,
Thanks for the answers. Gibbons' algorithm (from 2006) is a nice way
to generate the digits one after the other. However, it can get slow.
The mpmath approach is very fast, I think I will use that one. In a
script you can get the value of pi as a string with
str(mp.pi)
Best,
Laszlo
On
Hi,
It's not really a Python-related question, sorry for that. Does anyone
know why red-black trees got these colors in their names? Why not
blue-orange for instance? I'm just curious.
Thanks,
Laszlo
--
http://mail.python.org/mailman/listinfo/python-list
, Jabba Laci jabba.l...@gmail.com wrote:
Hi,
It's not really a Python-related question, sorry for that. Does anyone
know why red-black trees got these colors in their names? Why not
blue-orange for instance? I'm just curious.
http://programmers.stackexchange.com/questions/116614/where-does
Hi,
Unix's date command produces this output (example):
Thu Apr 5 22:49:42 CEST 2012
I would like to produce the same output with Python, without calling
date externally. Before doing it I'd like to ask the list if anyone
has an existing solution for this.
Thanks,
Laszlo
--
Hi,
Is the following function correct? Is the input file closed in order?
def read_data_file(self):
with open(self.data_file) as f:
return json.loads(f.read())
Thanks,
Laszlo
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I'm working on an interactive script. With raw_input user input is
read and the script produces some output and offers the prompt again.
I would like to add a clear screen feature, which would be activated
with CTRL+L. How to do that?
Another thing: raw_input waits until Enter but I'd like to
Have a look at IPython (http://ipython.org/). It can interact with the
normal shell very well.
Laszlo
On Sat, Feb 18, 2012 at 19:58, SherjilOzair sherjiloz...@gmail.com wrote:
Has it been considered to add shell features to python, such that it can be
used as a default shell, as a replacement
Hi,
Could someone please tell me what the following sorting algorithm is called?
Let an array contain the elements a_1, a_2, ..., a_N. Then:
for i = 1 to N-1:
for j = i+1 to N:
if a_j a_i then swap(a_j, a_i)
It's so simple that it's not mentioned anywhere. I guess it's called
Hi,
Either you're misremembering, or the algorithm you programmed 43 years
ago was not actually bubble sort. Quoting from Wikipedia:
Bubble sort, also known as sinking sort, is a simple sorting algorithm
that works by repeatedly stepping through the list to be sorted,
comparing each pair
You can click the Press me button as many times as you wish; it
retrieves and displays/prints the same HTML file on each click.
Hi,
Thanks for your reply. I forgot to mention that my first solution
created a headless browser, i.e. it didn't create any GUI. I would
like to keep it that way,
Hi,
I have a simple PyQt application that creates a webkit instance to
scrape AJAX web pages. It works well but I can't call it twice. I
think the application is not closed correctly, that's why the 2nd call
fails. Here is the code below. I also put it on pastebin:
http://pastebin.com/gkgSSJHY .
Hi,
In a unit test, I want to verify that a function returns a
cookielib.LWPCookieJar object. What is the correct way of doing that?
1) First I tried to figure out its type with type(return_value) but it
is type 'instance'
2) return_value.__class__ .__name__ gives 'LWPCookieJar', which is
Hi,
I'm reading the Essential SQLAlchemy book from O'Reilly. It explains
SqlAlch 0.4 but my current version is 0.7 and there are some
differences.
Here is an example from the book:
user_table = Table('tf_user', metadata,
Column('id', Integer, primary_key=True),
Hi,
I want to extract the URLs of all the posts on a tumblr blog. Let's
take for instance this blog: http://loveyourchaos.tumblr.com/archive .
If I download this page with a script, there are only 50 posts in the
HTML. If you scroll down in your browser to the end of the archive,
the browser will
Hi,
Thanks for the answer. Finally I found an API for this task:
http://www.tumblr.com/docs/en/api/v2#posts . It returns the required
data in JSON format.
Laszlo
The page isn't really that dynamic- HTTP doesn't allow for that.
Scrolling down the page triggers some Javascript. That Javascript
Why do you want to stop redis after your program terminates? Generally,
you just start redis up when the system boots and leave it running.
Hi,
OK, so it's more like MySQL or PostgeSQL, i.e. leave the server
running in the background. I wanted to use it like SQLite, i.e. let it
run only when
Hi,
I'm reading the redis documentation and there is one thing that
bothers me. For redis, you need to start a server on localhost. Is
there an easy way that my Python script starts this server
automatically? Before using my script, I don't want to start
redis-server each time. When my program
Hi,
I have Python 2.7 on my system. Today I wanted to try Google App
Engine but it runs on Python 2.5 at Google so I installed this version
on my machine next to v2.7 to avoid compatibility problems. However,
when I start the Python shell v2.5 and try to import something from
the GAE SDK (for
Hi,
I use Ubuntu and the Python packages on my system were either
installed with (1) apt-get, or with (2) pip. Since the number of
python packages in the Ubuntu repositories is limited, I had to
install several packages with pip.
Now I want to upgrade the packages that were installed with pip
Hi,
If I want to use the 'os.path' module, it's enought to import 'os':
import os
if os.path.isfile('/usr/bin/bash'):
print 'got it'
In other source codes I noticed that people write 'import os.path' in
this case. Which is better practice?
Thanks,
Laszlo
--
() must be passed the argument widget too.
Thanks,
Laszlo
On Wed, Aug 17, 2011 at 16:48, MrJean1 mrje...@gmail.com wrote:
Check that the app.quit method registered with atexit is called. E.g.
on Windows, that may not be the case.
/JeAN
On Aug 14, 9:39 am, Jabba Laci jabba.l...@gmail.com
Hi,
I wrote a simple GUI with pygtk to monitor mouse coordinates in
real-time. It works but when I close the application, the thread
doesn't stop and I can't figure out how to terminate it. Here is the
current source: https://gist.github.com/1144708 (83 lines).
Could you please help me out how
:
Jabba Laci wrote:
Could you please help me out how to close the application correctly?
I think you should put a flag into the code, which the parent might modify
it, so it will tell the child process to quit.
Then the flag should need to be read periodically to know whether is time to
quit
Hi,
I'd like to simplify the following string formatting:
solo = 'Han Solo'
jabba = 'Jabba the Hutt'
print {solo} was captured by {jabba}.format(solo=solo, jabba=jabba)
# Han Solo was captured by Jabba the Hutt
What I don't like here is this: solo=solo, jabba=jabba, i.e. the
same thing is
Hi,
If I want to check if a list is empty, which is the more pythonic way?
li = []
(1) if len(li) == 0:
...
or
(2) if not li:
...
Thanks,
Laszlo
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
Which is the preferred way of string formatting?
(1) the %s is %s % ('sky', 'blue')
(2) the {0} is {1}.format('sky', 'blue')
(3) the {} is {}.format('sky', 'blue')
As I know (1) is old style. (2) and (3) are new but (3) is only
supported from Python 2.7+.
Which one should be used?
Hi,
I'm just reading Robert M. Martin's book entitled Clean Code. In Ch.
5 he says that a function that is called should be below a function
that does the calling. This creates a nice flow down from top to
bottom.
However, when I write a Python script I do just the opposite. I start
with the
Hi,
I want to download a web page that is updated by AJAX. The page
requires no human interaction, it is updated automatically:
http://www.ncbi.nlm.nih.gov/nuccore/CP002059.1
If I download it with wget, I get a file of size 97 KB. The source is
full of AJAX calls, i.e. the content of the page is
I've heard you can drive a web browser using Selenium
(http://code.google.com/p/selenium/ ), have it visit the webpage and
run the JavaScript on it, and then grab the final result.
Hi,
Thanks for the info. I tried selenium, you can get the source with the
get_html_source() function but it
Hi,
I tried Pylint today and it gave me a warning for the function
filter. Is it deprecated? Is the usage of list comprehensions
encouraged? The transformation is not complicated, by the way:
replace filter( func, seq ) with [ x for x in seq if func(x) ] .
Thanks,
Laszlo
--
Hi,
I want to construct an XML file with lxml but I don't find how to add
the '?xml version=1.0?' header.
from lxml import etree as ET
html = ET.Element(html)
print ET.tostring(html)
simply prints
html/
Thanks,
Laszlo
--
http://mail.python.org/mailman/listinfo/python-list
My favorite approximation is: 355/113 (visualize 113355 split into two 113
355 and then do the division). The first 6 decimal places are the same.
3.141592920353982 = 355/113
vs
3.1415926535897931
Another, rather funny, approximation of the first 15 digits of pi is
to take the length of
Hi,
I'm trying to install a pypi package with pip. The installation is
done, but the permissions are not set correctly, thus I cannot import
it as a normal user.
Example:
sudo pip install termcolor
/usr/local/lib/python2.6/dist-packages/termcolor.py is created with
permissions 600
I can
Hi,
I'd like to create a simple alarm application that shows an alarm
window. The application should shut down automatically after 5
seconds. The problem is the following:
* If I keep the mouse outside of the window, the application keeps
running. Somehow self.Destroy() is not taken into account.
Hi,
2) I saw this in the documentation for Destroy() -- Frames and dialogs are
not destroyed immediately when this function is called -- they are added to a
list of windows to be deleted on idle time, when all the window's events have
been processed. That might be consistent with what
Hi,
I have a list that contains custom objects. When printing the list,
I'd like to have a readable result, i.e. I'd like to see the output of
the __str__ functions. See an example below. When I call print li, I
would like to get [3, 5]. How to do that?
Thanks,
Laszlo
==
class
Hi,
What do you suggest for playing mp3 files with Python? I found a
simple module (http://code.google.com/p/mp3play/) but it only works
with Windows. I'd need Linux support too.
Thanks,
Laszlo
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
Would someone explain how str[::-1] work? I'm new to Python and I only
saw so far the str[begin:end] notation. What is the second colon?
Thanks,
Laszlo
Here is a simplistic version that doesn't use fancy math:
str(24)
'24'
str(24)[::-1]
'42'
int(str(24)[::-1])
42
--
Hi,
I have some difficulties with list - tuple conversion:
t = ('a', 'b')
li = list(t) # tuple - list, works
print li # ['a', 'b']
tu = tuple(li) # list - tuple, error
print tu # what I'd expect: ('a', 'b')
The error message is: TypeError: 'tuple' object is not callable.
Thanks,
The error message is: TypeError: 'tuple' object is not callable.
You created a variable named tuple somewhere, which is shadowing the
built-in type. Rename that variable to something else.
Right, it was my bad. After removal the tuple() function works perfectly.
Thanks,
Laszlo
--
75 matches
Mail list logo