Hi.
Is there any way to control links browser from python?
I need to make some bot, twill don't work on my page, Selenium need's X server.
Maybe other way to do it?
On Linux, how can I find the default gateway for a local ip address/interface using python?
I saw the question "How to get internal IP, external IP and default gateway for UPnP", but the accepted solution only shows how to get the local IP address for a network interface on windows.
Thanks.
I'm using lxml to create an XML file from scratch;
having a code like this:
from lxml import etree
root = etree.Element("root")
root.set("interesting", "somewhat")
child1 = etree.SubElement(root, "test")
How do i write root Element object to an xml file using write() method of ElementTree class?
I have an RRD database, and I want to parse some of the data in it. I found this:
http://pypi.python.org/pypi/PyRRD/0.0.7
but it basically just calls the command line tools (no parsing).
Does anyone know of a library that will actually parse the output of rrdtool dump?
Thanks!
I have a Python function that gives back some read-write buffer:
>>> x = h.GetEXlow()
>>> x
<read-write buffer ptr 0xa2b8140, size 2147483647 at 0x8b73f80>
Now I would like to memset the whole buffer content to zero. (The size stated above is obviously wrong, but I can determine the size without problems.) How do I do this?
Hello!
I have this html code:
<table>
<tr>
<td class="test"><b><a href="">aaa</a></b></td>
<td class="test">bbb</td>
<td class="test">ccc</td>
<td class="test"><small>ddd</small></td>
</tr>
<tr>
<td class="test"><b><a href="">eee</a></b></td>
<td class="test">fff</td>
<td class="test">ggg</td>
<td class="test"><small>hhh</small></td>
</tr>
</table>
I use this Python code to extract all <td class="test"> with lxml module.
import urllib2
import lxml.html
code = urllib.urlopen("http://www.example.com/page.html").read()
html = lxml.html.fromstring(code)
result = html.xpath('//td[@class="test"][position() = 1 or position() = 4]')
It works good! The result is:
<td class="test"><b><a href="">aaa</a></b></td>
<td class="test"><small>ddd</small></td>
<td class="test"><b><a href="">eee</a></b></td>
<td class="test"><small>hhh</small></td>
(so the first and the fourth column of each <tr>)
Now, I have to extract:
aaa (the title of the link)
ddd (text between <small> tag)
eee (the title of the link)
hhh (text between <small> tag)
How could I extract these values?
(the problem is that I have to remove <b> tag and get the title of the anchor on the first column and remove <small> tag on the forth column)
Thank you!
How would I convert test cases made by Selenium IDE to Python without exporting every test case by hand? Is there any command line converter for that job?
In the end I want to use Selenium RC and Pythons build in unittest to test my websites.
Thanks a lot.
I have an App Engine app written in Google's webapp framework and I want to add some credit card handling to it.
Does a library already exist to integrate payment processing into an App Engine Python app?
I'd like to iterate over a list in Python several (say, 10) elements at a time, processing each slice one by one. I can think of a few ways to do this, but none seems obvious and clean. What is the most Pythonic way to do this?
Hey,
I need a method to get the data from an external editor.
def _get_content():
from subprocess import call
file = open(file, "w").write(some_name)
call(editor + " " + file, shell=True)
file.close()
file = open(file)
x = file.readlines()
[snip]
I personally think this is a very ugly way. You see I need to interact with an external editor and get the data.
Do you know any better approaches/have better ideas?
Hi,
My requirement is to search for jpeg images files in a directory using python script and list the file names. Can anyone help me on how to identify jpeg images files.
Thanks in advance...
I need to send a SOAP message (with Python SUDS) with strings encoded in 'iso-8859-2'.
Does anybody know how to do it?
SUDS raises the following exception when I invoke a method on a client with parameters encoded in 'iso-8859-2':
File "/home/bartek/myenv/lib/python2.5/site-packages/suds/sax/text.py", line 43, in __new__
result = super(Text, cls).__new__(cls, *args, **kwargs)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 10: ordinal not in range(128)
I am running ipython from sage and also am using some packages that aren't in sage (lxml, argparse) which are installed in my home directory. I have therefore ended up with a $PYTHONPATH of
$HOME/sage/local/lib/python:$HOME/lib/python
Python is reading and processing the first easy-install.pth it finds ($HOME/sage/local/lib/python/site-packages/easy-install.pth) but not the second, so eggs installed in $HOME/lib/python aren't added to the path. On reading the off-the-shelf site.py, I cannot for the life of me see why it's doing this.
Can someone enlighten me? Or advise how to nudge Python into reading both easy-install.pth files?
Consolidating both into one .pth file is a viable workaround for now, so this question is mostly for curiosity value.
What tools are available in Python to assist in parsing a context-free grammar?
Of course it is possible to roll my own, but I am looking for a generic tool that can generate a parser for a given CFG.
Here's the code I'm running:
import re
FIND_TERM = r'C:\\Program Files\\Microsoft SQL Server\\90\\DTS\\Binn\\DTExec\.exe'
rfind_term = re.compile(FIND_TERM,re.I)
REPLACE_TERM = 'C:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\DTExec.exe'
test = r'something C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTExec.exe something'
print rfind_term.sub(REPLACE_TERM,test)
And the result I get is:
something C:\Program Files\Microsoft SQL Server@\DTS\Binn\DTExec.exe something
Why is there an @ sign?
scenario: a modular app that loads .py modules on the fly as it works. programmer (me) wishes to edit the code of a module and and then re-load it into the program without halting execution.
can this be done?
i have tried running import a second time on an updated module.py, but the changes are not picked up
Hi all,
Is there a cross-platform way of getting the path to the temp directory in Python 2.6?
For example, under Linux that would be /tmp, while under XP C:\Documents and settings\\[user]\Application settings\Temp.
Thanks!
Looking to put together a 3D side-scrolling action platformer. Since this is my first time trying to put together a non-simple adventure game, I'm at a loss for which engine to consider.
I would prefer one that supports scripting in python, since that's my primary language. Without tight controls, the game will suck... so speed is a priority. Cross-platform is also important to me.
Any suggestions?
Hello.
I'm having a problem with the module subprocess.
I'm running a script from python through:
subprocess.Popen('./run_pythia.sh',shell=True).communicate()
and sometimes it just blocks and it doesn't finish to execute the script. Before I was using .wait() instead of .communicate() but then because of this:
http://dcreager.net/2009/08/06/subprocess-communicate-drawbacks/
I changed to .communicate(). Nevertheless the problem continues.
Can anyone help me?
This might be a really dumb question, however i've looked around online, etc. And have not seen a solid answer.
What i was wondering, is there a simple way to do something like this?
lines = open('something.txt', 'r').readlines()
for line in lines:
if line == '!':
# force iteration forward twice
line.next().next()
<etc>
Is there an easy way to do that in python?
My emacs hangs (Ubuntu 9 + emacs 23 + pyflakes) when I type """ quotes for string blocks.
anybody experience the same problem? I think, it may not be the emacs problem but some python mode or pyflakes which I use it for error checking.
Anybody hot around the issue? It really frustrating experience.
Consider this Python code for printing a list of comma separated values
for element in list:
print element + ",",
What is the preferred method for printing such that a comma does not appear if element is the final element in the list.
ex
a = [1, 2, 3]
for element in a
print str(element) +",",
output
1,2,3,
desired
1,2,3
Hi,
I'd like to write some Python unit tests for my Google App Engine. How can I set that up? Does someone happen to have some sample code which shows how to write a simple test?