how can I get the list of cross product pairs from a list of arbitrarily long lists in python? e.g.
a = [1,2,3]
b = [4,5,6]
crossproduct(a,b) should yield [[1,4], [1, 5], [1,6], ...]
thanks.
I'm learning perl and everytime I search for perl stuff in the internet I get some random page with people saying that perl should die because code written in it looks like a lesson in steganography. Then they say that python is clean and stuff like that. Now, I know that those comparisons are always stupid and made by fellows that feel that languages are a extension of their boring personality so, let me ask instead: can you give me the implementation of a widely known algorithm to deal with a data structure like red-black trees in both languages so I can compare?
I am writing a python script that needs to make a log entry whenever it's invoked. The log created by the script must not be changeable by the user (except root) who invoked the script. I tried the syslog module and while this does exactly what I want in terms of file permissions, I need to be able to put the resulting log file in an arbitrary location. How would I go about doing this?
Mechanize (Python) is failing with 401 for me to open http digest URLs. I googled and tried debugging but no success.
My code looks like this.
import mechanize
project = "test"
baseurl = "http://trac.somewhere.net"
loginurl = "%s/%s/login" % (baseurl, project)
b = mechanize.Browser()
b.add_password(baseurl, "user", "secret", "some Realm")
b.open(loginurl)
hi,
in python, how can a custom format-specification be added, to a class ? for example, if i write a matrix class, i would like to
define a '%M' (or some such) which would then dump the entire contents of the matrix...
thank you
kind regards
anupam
Hi, I'm new here and on python too, and i need a code to login an HTTPS webpage
the page is: ritaj.birzeit.edu
and how can i know if its correct username or password , can you help in this :)
Hi,
Does anybody know if there is a free python chess moves validation function available somewhere?
What I need. I have a diagram stored as a string, and move candidate. What I need is to see if move candidate is valid for the diagram.
Would be really interested to see examples, if possible.
In python the function random() generates a random float uniformly in the semi-open range [0.0, 1.0). In principle can it ever generate 0.0 (i.e. zero) and 1.0 (i.e. unity)? What is the scenario in practicality?
Hello.
Are there any modules for python, that can be used as tftp server? I tried Tftpy, but when I try to upload something, it says:
ERROR:tftpy:Write requests not implemented at this time.
In fact, it's the only function that I need.
i am using python 2.5.2. The following code not working.
def (self, text, findText):
index = text.find(findText)
print index
Although the findText is present in text, but it still returns None.
I have printed the values of text and findText and they are present.
Hello everybody!
Please advise library for working with soap in python.
Now, i'm trying to use "suds". And i can't undestand how get http headers from server reply
Code example:
from suds.client import Client
url = "http://10.1.0.36/money_trans/api3.wsdl"
client = Client(url)
login_res = client.service.Login("login", "password")
variable "login_res" contain xml answer and doesnt contain http headers. But i need to get session id from them.
Thank you.
I'm not a Perl user, but from this question deduced that it's exceedingly easy to retrieve the standard output of a program executed through a Perl script using something akin to:
$version = `java -version`;
How would I go about getting the same end result in Python? Does the above line retrieve standard error (equivalent to C++ std::cerr) and standard log (std::clog) output as well? If not, how can I retrieve those output streams as well?
Thanks,
Geoff
I'm writing a cross-platform python script that needs to know if and where Cygwin is installed if the platform is NT. Right now I'm just using a naive check for the existence of the default install path 'C:\Cygwin'. I would like to be able to determine the installation path programmatically.
The Windows registry doesn't appear to be an option since Cygwin no longer stores it's mount points in the registry. Because of this is it even possible to programmatically get a Cygwin installation path?
I am developing a python adapter to interact with a 3rd party website, without any json or xml api (http://www.class.noaa.gov/).
I have a problem when Travis CI run multiple python tests (of the The Travis CI Build Matrix) concurrently.
The project is on GitHub at ecolell/noaaclass and the .travis.yml file is:
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
install:
- "make deploy"
script: "make test-coverage-travis-ci" #nosetests
after_success:
- "make test-coveralls"
Specifically, I have a problem when at least 2 python versions were running their unit tests at the same time, because they use the same account of a website.
Is there any option to specify to The Build Matrix the execution of each python version in a secuential way?
Or maybe, Is there a better way to do this?
in a.txt i have the text(line one after the other)
login;user;name
login;user;name1
login;user
in b.txt i have the text
login;user
login;user
login;user;name2
after comparing it should display in a text file as
login;user;name
login;user;name1
login;user;name2....
How can it be done using python?
Following up to Regular expression to match hostname or IP Address?
and using Restrictions on valid host names as a reference, what is the most readable, concise way to match/validate a hostname/fqdn (fully qualified domain name) in Python? I've answered with my attempt below, improvements welcome.
I'm looking to reimplement some Tcl code that uses the socket -server construct [1].
What's the best option in Python for a small, industrial strength multi-user network-based server that includes event loop processing/integration?
[1] http://www.tcl.tk/man/tcl8.4/TclCmd/socket.htm
I'm learning perl and everytime I search for perl stuff in the internet I get some random page with people saying that perl should die because code written in it looks like a lesson in steganography. Then they say that python is clean and stuff like that. Now, I know that those comparisons are always stupid and made by fellows that feel that languages are a extension of their boring personality so, let me ask instead: can you give me the implementation of a widely known algorithm to deal with a data structure like red-black trees in both languages so I can compare?
Hello:
I am having some trouble with a very basic string issue in Python (that I can't figure out). Basically, I am trying to do the following:
'# read file into a string
myString = file.read()
'# Attempt to remove non breaking spaces
myString = myString.replace("\u00A0"," ")
'# however, when I print my string to output to console, I get:
Foo **<C2><A0>** Bar
I thought that the "\u00A0" was the escape code for unicode non breaking spaces, but apparently I am not doing this properly. Any ideas on what I am doing wrong?
What's the easiest way to count the longest consecutive repeat of a certain character in a string? For example, the longest consecutive repeat of "b" in the following string:
my_str = "abcdefgfaabbbffbbbbbbfgbb"
would be 6, since other consecutive repeats are shorter (3 and 2, respectively.) How can I do this in Python?
thanks.
Here's a simple function to do simple math operations, when i call this from other program using import, output i get is none. When i remove def function, everything is working fine. What's the problem with defining this function? I'm new to python.
def calci(a, op, b):
if op == '+':
c = a + b
elif op == '-':
c = a-b
elif op == '*':
c= a*b
elif op =='/':
if(b == 0):
print('can\'t divide')
c = a/b
print('value is',c)
return c
result = calci(12,'+', 12)
print(result) nter code here
How do I download a file with progress report using python but without supplying a filename.
I have tried urllib.urlretrieve but I seem to have to supply a filename for the download.
I've got the entire contents of a text file (at least a few KB) in string myStr.
Will the following code create a copy of the string (less the first character) in memory?
myStr = myStr[1:]
I'm hoping it just refers to a different location in the same internal buffer. If not, is there a more efficient way to do this?
Thanks!
Note: I'm using Python 2.5.
Does Python have a pool of all strings and are they (strings) singletons there?
More precise, in the following code one or two strings were created in memory:
a = str(num)
b = str(num)
?
Hi
I have a python file that has functions and classes. now I am writting another program (in another file). and I want to start the new file with running the old file (with the function and classes). I have tried using exec(path_2_oldFile.pyw) but it didn't work.
thanks for any help
Ariel