What is the most concise code you can write for dos2unix and unix2dos (CR/LF conversion) using Python 2.6+? These functions must accept a filename argument and do an in-place replacement.
In Python, if I want to get the first n characters of a string minus the last character, I do:
output = 'stackoverflow'
print output[:-1]
I can do the above in Ruby with:
output = 'stackoverflow'
output.reverse[1..output.length]
Is there another way to perform this action in Ruby?
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.
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?
hi;
i need grab to firefox address bar. how to get address bar url for python ? (i need second part other browsers chrome and safari grabbing address bar but firefox is urgently).
Thanks.
When debugging in PHP I frequently find it useful to simply stick a var_dump($foo, $bar, ...) in my code to show me the the what a variable is, what is value is, and the same for anything that it contains.
What is a good python equivalent for this?
I have seen several things in my Google searching that are somewhat equivalent, but nothing that is the same or better.
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'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 :)
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?
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
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.
Hi
i wont to store connection tu soap server in python session.
When i try to do this,
session['all']=Client(url)
I getting error:
MethodNotFound: Method not found: 'server.___getinitargs___'
How to store suds connection in session?
As a maintenance issue I need to routinely (3-5 times per year) copy a repository that is now has over 20 million files and exceeds 1.5 terabytes in total disk space. I am currently using RICHCOPY, but have tried others. RICHCOPY seems the fastest but I do not believe I am getting close to the limits of the capabilities of my XP machine.
I am toying around with using what I have read in The Art of Assembly Language to write a program to copy my files. My other thought is to start learning how to multi-thread in Python to do the copies.
I am toying around with the idea of doing this in Assembly because it seems interesting, but while my time is not incredibly precious it is precious enough that I am trying to get a sense of whether or not I will see significant enough gains in copy speed. I am assuming that I would but I only started really learning to program 18 months and it is still more or less a hobby. Thus I may be missing some fundamental concept of what happens with interpreted languages.
Any observations or experiences would be appreciated. Note, I am not looking for any code. I have already written a basic copy program in Python 2.6 that is no slower than RICHCOPY. I am looking for some observations on which will give me more speed. Right now it takes me over 50 hours to make a copy from a disk to a Drobo and then back from the Drobo to a disk. I have a LogicCube for when I am simply duplicating a disk but sometimes I need to go from a disk to Drobo or the reverse. I am thinking that given that I can sector copy a 3/4 full 2 terabyte drive using the LogicCube in under seven hours I should be able to get close to that using Assembly, but I don't know enough to know if this is valid. (Yes, sometimes ignorance is bliss)
The reason I need to speed it up is I have had two or three cycles where something has happened during copy (fifty hours is a long time to expect the world to hold still) that has caused me to have to trash the copy and start over. For example, last week the water main broke under our building and shorted out the power.
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
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
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.
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 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?
Say I've got an integer, 13941412, that I wish to separate into bytes (the number is actually a color in the form 0x00bbggrr). How would you do that? In c, you'd cast the number to a BYTE and then shift the bits. How do you cast to byte in Python?
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.
How can I (easily) take a string such as
'sin(x)*x^2'
which might be entered by a user at runtime and produce a python function that could be evaluated for any value of x? Does anyone know of any libraries or modules that takes care of this sort of thing?
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 want to access web service in Python or/and Perl scripts. What are the most popular and reliable libraries today?
I read this question, and I know about SOAPpy and ZSI. Can anybody say something about this libraries? Are they reliable enough for use in production?
I'm a little confused by the document when I tried to connect to the Mongodb.And I find it's different from mysql.I want to create a new database named "mydb" and insert some posts into it.The follows is what I'm trying.
from pymongo.connection import Connection
import datetime
host = 'localhost'
port = 27017
user = 'ucenter'
passwd = '123'
connection = Connection(host,port)
db = connection['mydb']
post = {'author':'mike',
'text':'my first blog post!',
'tags':['mongodb','python','pymongo'],
'date':datetime.datetime.utcnow()}
posts = db.posts
posts.insert(post)
#print str(db.collection_names())
And I got an error as pymongo.errors.OperationFailure: database error: unauthorized.How can I do the authorizing part?Thanks.