I was wondering if it's frowned upon to use the decorator module that comes with python. Should I be creating decorators using the original means or is it considered okay practice to use the module?
I'm using textmate for the first time basically, and I am lost as to what keys map to these funny symbols.
using python bundles, what keys do I press for:
run
run with tests
run project unit tests
Also, with textmate, do I actually define a project in textmate or do I just work on the files and textmate doesn't create its own .project type file ?
How would you write a list comprehension in python to generate a series of n-1 deltas between n items in an ordered list?
Example:
L = [5,9,2,1,7]
RES = [5-9,9-2,2-1,1-7] = [4,7,1,6] # absolute values
As some of you may know in python2.7/3.2 we'll get OrderedDict with PEP372 however one of the reason the PEP existed was because everyone did their own implementation and they were all sightly incompatible.
So which one of the 8 current implementations link text is backwards compatible with the 2.7 odict from python 2.7 in a way we can start using that now and depend on 2.7 in a couple of months?
I know about os.nice() it works perfect for parent process, but I need to do renice of my child subprocesses. I found way to do this, but it seems to be not very handy and too excessive:
os.system("renice -n %d %d" % ( new_nice, suprocess.pid ) )
And it isn't return resulting nice level after renicing.
Is there more clean way to renice subprocesses in python?
my python xml parser fails if there´s a comment at the beginnging of an xml file like::
<?xml version="1.0" encoding="utf-8"?>
<!-- Script version: "1"-->
<!-- Date: "07052010"-->
...
is it illegal to place a comment like this?
I'm using Python to read and write SAS datasets, using pyodbc and the SAS ODBC drivers. I can load the data perfectly well, but when I save the data, using something like:
cursor.execute('insert into dataset.test VALUES (?)', u'testing')
... I get a pyodbc.Error: ('HY004', '[HY004] [Microsoft][ODBC Driver Manager] SQL data type out of range (0) (SQLBindParameter)') error.
The problem seems to be the fact I'm passing a unicode string; what do I need to do to handle this?
I have domain on a shared hosting provider. How do I find the direct IP address of my domain using Python?
Is it possible to post to a script on my domain using the IP address and not the website itself?
Thanks.
I get an "unrecognized HTTP method" when trying to do a REPORT request using httplib and gae. Is there a workaround available? An httplib patch for gae? Do you I have to find another host in order to do this natively?
According to the docs, only certain fetch actions are valid: GET, POST, HEAD,
PUT, and DELETE: http://code.google.com/appengine/docs/python/urlfetch/
fetchfunction.html
This code should automatically connect players when they enter a game.
But the problem is when two users try to connect at the same time - in this case 2nd user can easily overwrite changes made by 1st user ('room_1' variable).
How could I make it thread safe?
def join(userId):
users = memcache.get('room_1')
users.append(userId)
memcache.set('room_1', users)
return users
I'm using Google App Engine (python) and going to implement simple game-server for exchanging peers given by Adobe Stratus.
I'm having trouble with the array or object that should be passed based on the response from __gettypes.
The __gettypes response:
[0] => struct CDataWrapper { schema;any; }
[1] => struct NewMember { MemberDetail MemberDetails;ArrayOfHobby Hobbies; }
[2] => struct MemberDetail { string Name; string Age; string Sex; }
[3] => struct ArrayOfHobby { Hobby Hobby; }
[4] => struct Hobby { string Name; string HoursUsedOnHobbyWeekly;boolean Favourite; }
... etc.
The methods are:
[0] => ReceiveMemberResponse ReceiveMember(ReceiveMember $parameters)
[1] => ReturnMemberResponse ReturnMember(ReturnMember $parameters)
So far I have this PHP:
$client = new SoapClient('http://domain.com?wsdl');
class MemberDetail
{
public $Name = '';
public $Age = '';
public $Sex = '';
}
$mc = new MemberDetail();
$mc->Name= 'Bob';
$mc->Age= '14';
$mc->Sex= 'Male';
$myParam = array('ReceiveMember'=>$mc);
$wcf = $client->ReceiveMember($myParam);
$wcfResult = $wcf->ReturnMember;
print_r($wcfResult)
when i call the page it returns:
Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.
I'm not really sure how to create the array or object to pass on as $myParam since im no expert with PHP either.
I'm using Python, for what it's worth, but will accept answers in any applicable language.
I've tried writing to /proc/$pid/cmdline, but that's a readonly file.
I've tried assigning a new string to sys.argv[0], but that has no perceptible impact.
Are there any other possibilities? My program is executing processes via os.system (equivalent to system(3)) so a general, *NIX-based solution using an additional spawning process would be fine.
I'm using python's sendmail in the following way:
msg = <SOME MESSAGE>
s = smtplib.SMTP('localhost')
s.sendmail(me, you, msg.as_string())
s.quit()
This usually works fine but it fails when the message is pretty big (around 200 lines). Any ideas what can cause this?
Hi all,
i am quite new in python.
I am receiving (through pyserial) string with data values.
How can I parse these data to particular data structure?
I know that
0-1 byte : id
2-5 byte : time1 =>but little endian (lsb first)
6-9 byte : time2 =>but little endian (lsb first)
and I looking for a function:
def parse_data(string):
data={}
data['id'] = ??
data['time1'] = ??
data['time2'] = ??
return data
thanks
Hello,
I have the following code in Python:
linkHTML = "<a href=\"page?q=%s\">click here</a>" % strLink
The problem is that when strLink has spaces in it the link shows up as
<a href="page?q=with space">click here</a>
I can use strLink.replace(" ","+")
But I am sure there are other characters which can cause errors. I tried using
urllib.quote(strLink)
But it doesn't seem to help.
Thanks!
Joel
Dear All,
Let say I have a model:
class A(db.Model):
B = db.StringProperty()
C = db.StringProperty()
How do I query if I wanted to search all empty property (not None, just empty) in C using python?
Would what mentioned in the title be possible? Python module style that is. See this example for what I exactly mean.
index.php
<?php
use Hello\World;
World::greet();
Hello/World.php
<?php
namespace Hello\World;
function greet() { echo 'Hello, World!'; }
Would this be possible?
How do I get the exact feed.xml/rss.xml/atom.xml path of a website?
For example, I supplied "http://www.example.com/news/today/this_is_a_news", but the rss is pointing to "http://www.example.com/rss/feed.xml", most modern browsers have this features already and I'm curious how did they get them.
Can you cite an example code in ruby, python or bash?
I need to run a lot of Django management commands in the crontab and want to log the output of each run to a special timestamped file. Is there a Django or Python module to help me do this or do I just have to roll my own?
I am using python and would like a simple api or regex to check for a domain name's validity. By validity I am the syntactical validity and not whether the domain name actually exists on the Internet or not.
I have this sample php code:
<?php
function response($a) {
@ob_end_clean();
header("Connection: close");
ob_start();
echo $a;
$length = ob_get_length();
header("Content-Length: $length");
ob_end_flush();
flush();
}
response("test1");
sleep(5);
echo "test2";
?>
now I make a connection to server from client by ajax.
now I want to server only send "test1" to me and then close the connection.
but connection not closed and wait 5 seconds and send me "test1 test2" !!
this is response headers from server to me :
X-Powered-By: PHP/5.3.27
Connection: close
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Cache-Control: private, no-cache, no-store, ------revalidate, no-transform
Transfer-Encoding: chunked
Content-Type: text/html
in response headers I do not see Content-Length header. is problem for this ??
or if not what I must do now for solving problem ??
hey dudes,
my first question anyway,
i have made a single user dungeon and am looking to change it in to a multi user dungoen how can i do this by the way im using python to make the sud in to a mud lol