title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
splitting integer in python? | 1,906,717 | <p>my integer input is suppose 12345 , i want to split and put it into an array as 1,2,3,4,5 . How will i be able to do it?</p>
| 11 | 2009-12-15T11:09:00Z | 1,906,727 | <pre><code>>>> [int(i) for i in str(12345)]
[1, 2, 3, 4, 5]
</code></pre>
| 33 | 2009-12-15T11:12:22Z | [
"python"
] |
splitting integer in python? | 1,906,717 | <p>my integer input is suppose 12345 , i want to split and put it into an array as 1,2,3,4,5 . How will i be able to do it?</p>
| 11 | 2009-12-15T11:09:00Z | 1,906,766 | <pre><code>[int(i) for i in str(number)]
</code></pre>
<p>or, if do not want to use a list comprehension or you want to use a base different from 10 </p>
<pre><code>from __future__ import division # for compatibility of // between Python 2 and 3
def digits(number, base=10):
assert number >= 0
if number == ... | 5 | 2009-12-15T11:19:36Z | [
"python"
] |
splitting integer in python? | 1,906,717 | <p>my integer input is suppose 12345 , i want to split and put it into an array as 1,2,3,4,5 . How will i be able to do it?</p>
| 11 | 2009-12-15T11:09:00Z | 1,906,874 | <p>like @nd says but using the built-in function of int to convert to a different base</p>
<pre><code>>>> [ int(i,16) for i in '0123456789ABCDEF' ]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
>>> [int(i,2) for i in "100 010 110 111".split()]
[4, 2, 6, 7]
</code></pre>
<p>I don't know wha... | 2 | 2009-12-15T11:40:24Z | [
"python"
] |
splitting integer in python? | 1,906,717 | <p>my integer input is suppose 12345 , i want to split and put it into an array as 1,2,3,4,5 . How will i be able to do it?</p>
| 11 | 2009-12-15T11:09:00Z | 24,867,136 | <p>according to the previous answers, strings are iterable, so if you need a list of your digits you can append it one by one using:</p>
<pre><code>digits = []
digits += str(12345)
</code></pre>
| 0 | 2014-07-21T14:06:15Z | [
"python"
] |
python unbound method again | 1,906,926 | <p>This gets me into difficult time (sorry, i am still very new to python)
Thank you for any kind of help.</p>
<p>The error</p>
<blockquote>
<pre><code>print Student.MostFrequent() TypeError: unbound method
</code></pre>
<p>MostFrequent() must be called with
Student instance as first argument
(got nothing in... | 3 | 2009-12-15T11:51:28Z | 1,906,949 | <p>use <code>Student().MostFrequent()</code></p>
<p><strong>edit</strong>:</p>
<p>beware that you use class attributes and this is dangerous. here an example:</p>
<pre><code>>>> class Person:
... name = None
... hobbies = []
... def __init__(self, name):
... self.name = name
...
>>> a = Perso... | 7 | 2009-12-15T11:57:16Z | [
"python",
"class"
] |
python unbound method again | 1,906,926 | <p>This gets me into difficult time (sorry, i am still very new to python)
Thank you for any kind of help.</p>
<p>The error</p>
<blockquote>
<pre><code>print Student.MostFrequent() TypeError: unbound method
</code></pre>
<p>MostFrequent() must be called with
Student instance as first argument
(got nothing in... | 3 | 2009-12-15T11:51:28Z | 1,906,952 | <p>in your class def, the method definition </p>
<pre><code>def MostFrequent(self,mostFrequent):
</code></pre>
<p>has the extra variable <em>mostFrequent</em> that you probably don't want there. Try changing to :</p>
<pre><code>def MostFrequent(self):
</code></pre>
| -1 | 2009-12-15T11:57:43Z | [
"python",
"class"
] |
python unbound method again | 1,906,926 | <p>This gets me into difficult time (sorry, i am still very new to python)
Thank you for any kind of help.</p>
<p>The error</p>
<blockquote>
<pre><code>print Student.MostFrequent() TypeError: unbound method
</code></pre>
<p>MostFrequent() must be called with
Student instance as first argument
(got nothing in... | 3 | 2009-12-15T11:51:28Z | 1,906,957 | <p>You only rarely call methods on a class definition (<code>Student</code>)</p>
<p>Almost always, you create an instance of the class</p>
<pre><code>someStudent = Student(someRow)
</code></pre>
<p>Then you call the method on the instance ("object"), <code>someStudent</code>.</p>
<pre><code>someStudent.MostFrequen... | 0 | 2009-12-15T11:58:50Z | [
"python",
"class"
] |
python unbound method again | 1,906,926 | <p>This gets me into difficult time (sorry, i am still very new to python)
Thank you for any kind of help.</p>
<p>The error</p>
<blockquote>
<pre><code>print Student.MostFrequent() TypeError: unbound method
</code></pre>
<p>MostFrequent() must be called with
Student instance as first argument
(got nothing in... | 3 | 2009-12-15T11:51:28Z | 1,906,958 | <p><strong>first</strong> read <a href="http://www.python.org/dev/peps/pep-0008/">PEP-8</a> on naming conventions:</p>
<blockquote>
<p>Method Names and Instance Variables</p>
</blockquote>
<pre><code> Use the function naming rules: lowercase with words separated by
underscores as necessary to improve readability... | 7 | 2009-12-15T11:58:52Z | [
"python",
"class"
] |
python unbound method again | 1,906,926 | <p>This gets me into difficult time (sorry, i am still very new to python)
Thank you for any kind of help.</p>
<p>The error</p>
<blockquote>
<pre><code>print Student.MostFrequent() TypeError: unbound method
</code></pre>
<p>MostFrequent() must be called with
Student instance as first argument
(got nothing in... | 3 | 2009-12-15T11:51:28Z | 1,906,962 | <p>Student.MostFrequent means You're trying to use static method, not instance method. So You must first create instance by calling Student() and then call MostFrequent() on it.</p>
<p>P.S.: If this is not part of some arcane project, I urge you to follow PEP 8 and use most_frequent as method name.</p>
| 0 | 2009-12-15T11:59:26Z | [
"python",
"class"
] |
python unbound method again | 1,906,926 | <p>This gets me into difficult time (sorry, i am still very new to python)
Thank you for any kind of help.</p>
<p>The error</p>
<blockquote>
<pre><code>print Student.MostFrequent() TypeError: unbound method
</code></pre>
<p>MostFrequent() must be called with
Student instance as first argument
(got nothing in... | 3 | 2009-12-15T11:51:28Z | 1,906,975 | <p>First, I recommend making function names lower case only.</p>
<p>The error you get results from the usage of <code>MostFrequent</code> as a static method. For this to work, you need to explicitly pass an instance of <code>Student</code> as first argument.</p>
<p>If called directly on an instance of <code>Student</... | 1 | 2009-12-15T12:02:25Z | [
"python",
"class"
] |
python unbound method again | 1,906,926 | <p>This gets me into difficult time (sorry, i am still very new to python)
Thank you for any kind of help.</p>
<p>The error</p>
<blockquote>
<pre><code>print Student.MostFrequent() TypeError: unbound method
</code></pre>
<p>MostFrequent() must be called with
Student instance as first argument
(got nothing in... | 3 | 2009-12-15T11:51:28Z | 1,907,004 | <p>What you probably want is to define <code>most_frequent</code> as a <a href="http://docs.python.org/library/functions.html#classmethod" rel="nofollow"><code>classmethod</code></a>:</p>
<pre><code>@classmethod
def most_frequent(cls):
for choice in cls.choice_list:
cls.choice_dict[choice] = cls.choice_dic... | 1 | 2009-12-15T12:09:17Z | [
"python",
"class"
] |
Read https url from Python with basic access authentication | 1,906,977 | <p>How do you open https url in Python?</p>
<pre><code>import urllib2
url = "https://user:password@domain.com/path/
f = urllib2.urlopen(url)
print f.read()
</code></pre>
<p>gives:</p>
<pre><code>httplib.InvalidURL: nonnumeric port: 'password@domain.com'
</code></pre>
| 4 | 2009-12-15T12:02:58Z | 1,907,013 | <p>You cannot pass credentials to <code>urllib2.open</code> like that. In your case, <code>user</code> is interpreted as the domain name, while <code>password@domain.com</code> is interpreted as the port number. </p>
| 2 | 2009-12-15T12:10:38Z | [
"python",
"authentication",
"https",
"passwords"
] |
Read https url from Python with basic access authentication | 1,906,977 | <p>How do you open https url in Python?</p>
<pre><code>import urllib2
url = "https://user:password@domain.com/path/
f = urllib2.urlopen(url)
print f.read()
</code></pre>
<p>gives:</p>
<pre><code>httplib.InvalidURL: nonnumeric port: 'password@domain.com'
</code></pre>
| 4 | 2009-12-15T12:02:58Z | 1,907,018 | <p>Please read about the urllib2 password manager and the basic authentication handler as well as the digest authentication handler.</p>
<p><a href="http://docs.python.org/library/urllib2.html#abstractbasicauthhandler-objects">http://docs.python.org/library/urllib2.html#abstractbasicauthhandler-objects</a></p>
<p><a ... | 5 | 2009-12-15T12:11:42Z | [
"python",
"authentication",
"https",
"passwords"
] |
Read https url from Python with basic access authentication | 1,906,977 | <p>How do you open https url in Python?</p>
<pre><code>import urllib2
url = "https://user:password@domain.com/path/
f = urllib2.urlopen(url)
print f.read()
</code></pre>
<p>gives:</p>
<pre><code>httplib.InvalidURL: nonnumeric port: 'password@domain.com'
</code></pre>
| 4 | 2009-12-15T12:02:58Z | 1,907,019 | <p>If you want to pass username and password information to <code>urllib2</code> you'll need to use an <code>HTTPBasicAuthHandler</code>.</p>
<p><a href="http://www.voidspace.org.uk/python/articles/authentication.shtml#doing-it-properly" rel="nofollow">Here's a tutorial showing you how to do it.</a></p>
| 3 | 2009-12-15T12:11:48Z | [
"python",
"authentication",
"https",
"passwords"
] |
Read https url from Python with basic access authentication | 1,906,977 | <p>How do you open https url in Python?</p>
<pre><code>import urllib2
url = "https://user:password@domain.com/path/
f = urllib2.urlopen(url)
print f.read()
</code></pre>
<p>gives:</p>
<pre><code>httplib.InvalidURL: nonnumeric port: 'password@domain.com'
</code></pre>
| 4 | 2009-12-15T12:02:58Z | 1,910,005 | <p>This has never failed me</p>
<pre><code>import urllib2, base64
username = 'foo'
password = 'bar'
auth_encoded = base64.encodestring('%s:%s' % (username, password))[:-1]
req = urllib2.Request('https://somewebsite.com')
req.add_header('Authorization', 'Basic %s' % auth_encoded)
try:
response = urllib2.urlopen(re... | 9 | 2009-12-15T20:02:53Z | [
"python",
"authentication",
"https",
"passwords"
] |
Convert single-quoted string to double-quoted string | 1,906,991 | <p>I want to check whether the given string is single- or double-quoted. If it is single quote I want to convert it to be double quote, else it has to be same double quote.</p>
| 9 | 2009-12-15T12:06:37Z | 1,907,009 | <p>The difference is only on input. They are the same.</p>
<pre><code>s = "hi"
t = 'hi'
s == t
</code></pre>
<blockquote>
<p>True</p>
</blockquote>
<p>You can even do:</p>
<pre><code>"hi" == 'hi'
</code></pre>
<blockquote>
<p>True</p>
</blockquote>
<p>Providing both methods is useful because you can for exam... | 5 | 2009-12-15T12:09:54Z | [
"python",
"string"
] |
Convert single-quoted string to double-quoted string | 1,906,991 | <p>I want to check whether the given string is single- or double-quoted. If it is single quote I want to convert it to be double quote, else it has to be same double quote.</p>
| 9 | 2009-12-15T12:06:37Z | 1,907,014 | <p>There is no difference between "single quoted" and "double quoted" strigns in Python:
both are parsed internally to string objects.</p>
<p>I mean:</p>
<pre><code>a = "European Swallow"
b = 'African Swallow'
</code></pre>
<p>Are internally string objects.</p>
<p>However you might mean to add an extra quote inside... | 6 | 2009-12-15T12:10:50Z | [
"python",
"string"
] |
Convert single-quoted string to double-quoted string | 1,906,991 | <p>I want to check whether the given string is single- or double-quoted. If it is single quote I want to convert it to be double quote, else it has to be same double quote.</p>
| 9 | 2009-12-15T12:06:37Z | 1,907,017 | <p>In Python, there is no difference between strings that are single or double quoted, so I don't know why you would want to do this. However, if you actually mean single quote characters inside a string, then to replace them with double quotes, you would do this: <code>mystring.replace('\'', '"')</code></p>
| 1 | 2009-12-15T12:11:35Z | [
"python",
"string"
] |
python http handler | 1,907,071 | <p>I want something like <a href="http://docs.python.org/library/basehttpserver.html#BaseHTTPServer.BaseHTTPRequestHandler" rel="nofollow"><code>BaseHTTPRequestHandler</code></a>, except that I don't want it to bind to any sockets; I want to handle the raw HTTP data to and from it myself. Is there a good way that I ca... | 4 | 2009-12-15T12:22:10Z | 1,907,633 | <p><code>BaseHTTPRequestHandler</code> derives from <code>StreamRequestHandler</code>, which basically reads from file <code>self.rfile</code> and writes to <code>self.wfile</code>, so you can derive a class from <code>BaseHTTPRequestHandler</code> and supply your own rfile and wfile e.g.</p>
<pre><code>import StringI... | 4 | 2009-12-15T13:55:05Z | [
"python",
"http",
"request",
"handler"
] |
how can I make 'between' query with web2py.DAL? | 1,907,088 | <p>I'm trying to make a query function that accepts two datetime.date object(start_date and end_date), and return all records with a related field that's between start_date and end_date.
However, I found nothing like a <code>between</code> function in the web2py manual, so I implement it this way:</p>
<pre><code> ... | 1 | 2009-12-15T12:24:59Z | 1,908,096 | <p><code>db((db.mytable.create_date>=query_dict['create_date1'])&(db.mytable.create_date<=query_dict['create_date2'])).select()</code></p>
| 1 | 2009-12-15T15:11:28Z | [
"python",
"web2py"
] |
Is it possible to access an xcf active memory server with python? | 1,907,102 | <p>I'm playing around with the <a href="https://code.ai.techfak.uni-bielefeld.de/trac/xcf" rel="nofollow">XCF</a> active memory server. Is there a python library to access the contents of the active memory server?</p>
<h3>Related:</h3>
<p><a href="http://stackoverflow.com/questions/1901568/how-to-write-data-to-the-ac... | 0 | 2009-12-15T12:28:03Z | 1,911,849 | <p>According to <a href="http://xcf.sourceforge.net/docs/am/index.html" rel="nofollow">their documentation</a>, the answer appears to be "yes".</p>
| 0 | 2009-12-16T02:13:44Z | [
"python",
"xcf",
"active-memory"
] |
Is it possible to access an xcf active memory server with python? | 1,907,102 | <p>I'm playing around with the <a href="https://code.ai.techfak.uni-bielefeld.de/trac/xcf" rel="nofollow">XCF</a> active memory server. Is there a python library to access the contents of the active memory server?</p>
<h3>Related:</h3>
<p><a href="http://stackoverflow.com/questions/1901568/how-to-write-data-to-the-ac... | 0 | 2009-12-15T12:28:03Z | 1,920,951 | <p>According to one of the developers there is an outdated version of a python API for publish and subscribe over XCF. This API is not capable of contacting an active memory server. </p>
| 0 | 2009-12-17T10:56:10Z | [
"python",
"xcf",
"active-memory"
] |
Whether to simplify two stage regular expression? | 1,907,137 | <p>I'm newbie in Python, but this question is not a homework (actually this code helps to generate RSS on my Subversion server).</p>
<p>I have an array of strings in the <code>info_lines</code> variable. And I want to replace each occurrence of the bug ID. My current code looks like the following:</p>
<pre><code>for ... | 2 | 2009-12-15T12:34:15Z | 1,907,194 | <p>I would say that it's fine as-is, although I personally would prefer different syntax for bug numbers. I would differentiate them from bare numbers by either having "bug 144", "issue 196" or just "#153". That means they can then be embedded in a longer message, to provide clearer context. This is especially helpful ... | 0 | 2009-12-15T12:45:41Z | [
"python",
"regex"
] |
Whether to simplify two stage regular expression? | 1,907,137 | <p>I'm newbie in Python, but this question is not a homework (actually this code helps to generate RSS on my Subversion server).</p>
<p>I have an array of strings in the <code>info_lines</code> variable. And I want to replace each occurrence of the bug ID. My current code looks like the following:</p>
<pre><code>for ... | 2 | 2009-12-15T12:34:15Z | 1,907,987 | <p>No, there's not much of a better way to do it. The replacement code messes up the case where there are bug numbers and other numbers on the same line, but even so, you're not getting away from two <code>re</code>s because you want support for a comma-separated bug list.</p>
<pre><code>import re
info_lines = [
... | 2 | 2009-12-15T14:55:00Z | [
"python",
"regex"
] |
How can I express base class method calling derived virtual? | 1,907,182 | <p>what's the way to do in python the following in C++?</p>
<pre><code>B* b = new D();
b->virtual_fn();
</code></pre>
<p>Which would call virtual_fn in D. Are there a form of references to do this?</p>
| 1 | 2009-12-15T12:43:30Z | 1,907,227 | <p>Effectively, all instance methods in Python are virtual and types are inferred. For example, this works:</p>
<pre><code>class Vehicle:
def __init__(self, lp):
self.license_plate = lp
def alert(self):
raise NotImplementedError("Must implement this!")
class Boat(Vehicle):
def alert(self):
print "ho... | 2 | 2009-12-15T12:49:38Z | [
"python",
"oop"
] |
How can I express base class method calling derived virtual? | 1,907,182 | <p>what's the way to do in python the following in C++?</p>
<pre><code>B* b = new D();
b->virtual_fn();
</code></pre>
<p>Which would call virtual_fn in D. Are there a form of references to do this?</p>
| 1 | 2009-12-15T12:43:30Z | 1,907,309 | <p>In Python, values have types not variables. The latter are simply useful names for the values that they are currently bound to. Since variables do not have types, if you create a <code>D</code> object and bind a variable to it, then you get the methods explicitly defined by the <code>D</code> class and any in the ... | 2 | 2009-12-15T13:03:50Z | [
"python",
"oop"
] |
App engine templates | 1,907,187 | <p>In app engine there a way to use templates a bit more like php/javascript(document.write)?</p>
<p>for instance i would rather do:</p>
<pre><code><html>
<python>
print "Hello world"
</python>
</html>
</code></pre>
<p>rather than all the {IF } {ELSE } django stuff.</p>
| 1 | 2009-12-15T12:44:00Z | 1,907,461 | <p>You want embedded python in html page for that look into mako (<a href="http://www.makotemplates.org/" rel="nofollow">http://www.makotemplates.org/</a>), you don't even need print e.g.</p>
<pre><code><%inherit file="base.html"/>
<%
rows = [[v for v in range(0,10)] for row in range(0,10)]
%>
<tabl... | 3 | 2009-12-15T13:27:46Z | [
"python",
"google-app-engine"
] |
App engine templates | 1,907,187 | <p>In app engine there a way to use templates a bit more like php/javascript(document.write)?</p>
<p>for instance i would rather do:</p>
<pre><code><html>
<python>
print "Hello world"
</python>
</html>
</code></pre>
<p>rather than all the {IF } {ELSE } django stuff.</p>
| 1 | 2009-12-15T12:44:00Z | 1,908,979 | <p>The simplest way is to use <a href="http://docs.python.org/library/string.html#template-strings" rel="nofollow">string templates</a> from the standard library.</p>
| 0 | 2009-12-15T17:16:20Z | [
"python",
"google-app-engine"
] |
App engine templates | 1,907,187 | <p>In app engine there a way to use templates a bit more like php/javascript(document.write)?</p>
<p>for instance i would rather do:</p>
<pre><code><html>
<python>
print "Hello world"
</python>
</html>
</code></pre>
<p>rather than all the {IF } {ELSE } django stuff.</p>
| 1 | 2009-12-15T12:44:00Z | 1,909,204 | <p>One of the web programming best practices it to not mix business or page logic with HTML. That's why the templates were created after all, so the code can process the request, call the appropriate logic and prepare the objects used to display the response before any output is made. Why do you want to go the other wa... | 0 | 2009-12-15T17:55:34Z | [
"python",
"google-app-engine"
] |
App engine templates | 1,907,187 | <p>In app engine there a way to use templates a bit more like php/javascript(document.write)?</p>
<p>for instance i would rather do:</p>
<pre><code><html>
<python>
print "Hello world"
</python>
</html>
</code></pre>
<p>rather than all the {IF } {ELSE } django stuff.</p>
| 1 | 2009-12-15T12:44:00Z | 1,912,373 | <p>The Tornado project's <a href="http://www.tornadoweb.org/documentation#templates" rel="nofollow">template</a> module allows the insertion of python code, and it's very fast as well. It works well within App Engine, despite being designed to work with the rest of the Tornado framework and the Tornado HTTP server.</p... | 2 | 2009-12-16T04:50:30Z | [
"python",
"google-app-engine"
] |
How do I check if it's Monday to Friday and the time is between 10 AM to 3 PM? | 1,907,196 | <p>In python how do I check if its a weekday (Monday - Friday) and the time is between 10 AM to 3 PM?</p>
| 9 | 2009-12-15T12:45:45Z | 1,907,219 | <pre><code>>>> import datetime
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2009, 12, 15, 12, 45, 33, 781000)
>>> now.isoweekday()
2 # Tuesday
</code></pre>
<p>time between 10 a.m. and 3 p.m. is right there as well</p>
| 1 | 2009-12-15T12:48:17Z | [
"python",
"datetime"
] |
How do I check if it's Monday to Friday and the time is between 10 AM to 3 PM? | 1,907,196 | <p>In python how do I check if its a weekday (Monday - Friday) and the time is between 10 AM to 3 PM?</p>
| 9 | 2009-12-15T12:45:45Z | 1,907,247 | <pre><code>>>> import datetime
>>> d = datetime.datetime.now()
# => datetime.datetime(2009, 12, 15, 13, 50, 35, 833175)
# check if weekday is 1..5
>>> d.isoweekday() in range(1, 6)
True
# check if hour is 10..15
>>> d.hour in range(10, 15)
True
# check if minute is 30
>>... | 14 | 2009-12-15T12:52:36Z | [
"python",
"datetime"
] |
nested looping in python | 1,907,519 | <p>in a string suppose 12345 , i want to take nested loops , so that i would be able to iterate through the string in this following way :-</p>
<ol>
<li>1, 2, 3, 4, 5 would be taken as integers </li>
<li>12, 3, 4,5 as integers</li>
<li>1, 23, 4, 5 as integers</li>
<li>1, 2, 34, 5 as integers
...</li>
</ol>
<p>And so... | 1 | 2009-12-15T13:36:33Z | 1,907,544 | <p>This smells a bit like homework.</p>
<p>Try writing down the successive outputs, one per line, and look for a pattern. See if you can explain that pattern with slices of the input string. Then look for a numeric pattern to the slicing.</p>
<p>Also, please edit your question to put quotes around your strings. Wh... | 1 | 2009-12-15T13:43:00Z | [
"python"
] |
nested looping in python | 1,907,519 | <p>in a string suppose 12345 , i want to take nested loops , so that i would be able to iterate through the string in this following way :-</p>
<ol>
<li>1, 2, 3, 4, 5 would be taken as integers </li>
<li>12, 3, 4,5 as integers</li>
<li>1, 23, 4, 5 as integers</li>
<li>1, 2, 34, 5 as integers
...</li>
</ol>
<p>And so... | 1 | 2009-12-15T13:36:33Z | 1,907,567 | <p>You can do the inner traversals by following code, the first traversal is trivial.</p>
<pre><code>s = '12345'
chars = [c for c in s]
for i in range(len(s) - 1):
print '%d:' % i,
for el in chars[:i] + [chars[i] + chars[i + 1]] + chars[i + 2:]:
print el,
print
</code></pre>
| 0 | 2009-12-15T13:46:34Z | [
"python"
] |
nested looping in python | 1,907,519 | <p>in a string suppose 12345 , i want to take nested loops , so that i would be able to iterate through the string in this following way :-</p>
<ol>
<li>1, 2, 3, 4, 5 would be taken as integers </li>
<li>12, 3, 4,5 as integers</li>
<li>1, 23, 4, 5 as integers</li>
<li>1, 2, 34, 5 as integers
...</li>
</ol>
<p>And so... | 1 | 2009-12-15T13:36:33Z | 1,907,570 | <pre><code>number = 12345
str_number = str(number)
output = []
for index, part in enumerate(str_number[:-1]):
output_part = []
for second_index, second_part in enumerate(str_number):
if index == second_index:
continue
elif index == second_index - 1:
output_part.append(i... | 0 | 2009-12-15T13:46:52Z | [
"python"
] |
Python: Import a file and convert to a list | 1,907,538 | <p>I need help with importing a file and converting each line into a list.</p>
<p>An example of the file would look like:</p>
<pre><code>p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
</code></pre>
<p>The first line beginning with p is a header and the rest are clauses.
Each clause line must begi... | 2 | 2009-12-15T13:40:51Z | 1,907,560 | <p>look at this:
<a href="http://docs.python.org/tutorial/inputoutput.html" rel="nofollow">Input Output Python Documentation</a></p>
<p>The Keyword here is "readline".</p>
<p>If you have problems using it...reedit your question</p>
| 0 | 2009-12-15T13:45:29Z | [
"python",
"file",
"list",
"input"
] |
Python: Import a file and convert to a list | 1,907,538 | <p>I need help with importing a file and converting each line into a list.</p>
<p>An example of the file would look like:</p>
<pre><code>p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
</code></pre>
<p>The first line beginning with p is a header and the rest are clauses.
Each clause line must begi... | 2 | 2009-12-15T13:40:51Z | 1,907,566 | <p>If you want all of the values in a flat list, the code would look as follows:</p>
<pre><code>ls=[]
for line in open( "input.txt", "r" ).readlines():
for value in line.split( ' ' ):
ls.append( value )
</code></pre>
<p>If you just want the lines in a list then you can stop at readlines().</p>
| 0 | 2009-12-15T13:46:09Z | [
"python",
"file",
"list",
"input"
] |
Python: Import a file and convert to a list | 1,907,538 | <p>I need help with importing a file and converting each line into a list.</p>
<p>An example of the file would look like:</p>
<pre><code>p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
</code></pre>
<p>The first line beginning with p is a header and the rest are clauses.
Each clause line must begi... | 2 | 2009-12-15T13:40:51Z | 1,907,592 | <p>The following line will create a list where each item is a list. The inner list is one line thats split up into "words".</p>
<pre><code>li = [i.strip().split() for i in open("input.txt").readlines()]
</code></pre>
<p>I put the code snippet you posted into a input.txt file in c:\temp and ran this line. Is the outpu... | 6 | 2009-12-15T13:49:19Z | [
"python",
"file",
"list",
"input"
] |
Python: Import a file and convert to a list | 1,907,538 | <p>I need help with importing a file and converting each line into a list.</p>
<p>An example of the file would look like:</p>
<pre><code>p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
</code></pre>
<p>The first line beginning with p is a header and the rest are clauses.
Each clause line must begi... | 2 | 2009-12-15T13:40:51Z | 1,908,285 | <pre><code>fh=open("file")
mylist=[]
header=fh.readline().rstrip()
if not header.startswith("p wncf") :
print "error"
header=header.split()
mylist.append(header)
if len(header) != 5:
print "error"
if False in map(str.isdigit, header[2:]):
print "Error"
for line in fh:
line=line.rstrip().split()
if F... | 0 | 2009-12-15T15:41:01Z | [
"python",
"file",
"list",
"input"
] |
Python: Import a file and convert to a list | 1,907,538 | <p>I need help with importing a file and converting each line into a list.</p>
<p>An example of the file would look like:</p>
<pre><code>p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
</code></pre>
<p>The first line beginning with p is a header and the rest are clauses.
Each clause line must begi... | 2 | 2009-12-15T13:40:51Z | 1,908,384 | <pre><code>fileName=open("d:/foo.bar")
lines = [i for i in fileName.readlines()]
</code></pre>
<p>hope that helps :D</p>
| 2 | 2009-12-15T15:54:57Z | [
"python",
"file",
"list",
"input"
] |
Python: Import a file and convert to a list | 1,907,538 | <p>I need help with importing a file and converting each line into a list.</p>
<p>An example of the file would look like:</p>
<pre><code>p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
</code></pre>
<p>The first line beginning with p is a header and the rest are clauses.
Each clause line must begi... | 2 | 2009-12-15T13:40:51Z | 1,908,556 | <pre><code>p = open('filename')
#List:
linelist = [line for line in p.readlines()]
"""
But I prefer creating a dictionary as I find them more useful at times. Example here is very trivial. You can use the list index as a line number also.
"""
#Dictionary:
linedict = dict([(no, line) for no, line in enumerate(p.readl... | 2 | 2009-12-15T16:15:31Z | [
"python",
"file",
"list",
"input"
] |
Python: Import a file and convert to a list | 1,907,538 | <p>I need help with importing a file and converting each line into a list.</p>
<p>An example of the file would look like:</p>
<pre><code>p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
</code></pre>
<p>The first line beginning with p is a header and the rest are clauses.
Each clause line must begi... | 2 | 2009-12-15T13:40:51Z | 1,910,370 | <p>To build a list of only the lines in the file that contain at least two integers and end with a zero, use a regular expression:</p>
<pre><code>import re
p = re.compile(r'^((\-?\d*\s+){2,})0$')
with open(filename, 'rb') as f:
seq = [line.strip() for line in f if p.match(line)]
</code></pre>
| 1 | 2009-12-15T21:00:41Z | [
"python",
"file",
"list",
"input"
] |
Python: Import a file and convert to a list | 1,907,538 | <p>I need help with importing a file and converting each line into a list.</p>
<p>An example of the file would look like:</p>
<pre><code>p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
</code></pre>
<p>The first line beginning with p is a header and the rest are clauses.
Each clause line must begi... | 2 | 2009-12-15T13:40:51Z | 1,914,976 | <p>You're not providing all the details, but i assume that:</p>
<ul>
<li>there's only 1 header line at the beginning and you don't need what's in it</li>
<li>the other lines only contain integers</li>
<li>you don't need to retain the trailing '0'</li>
</ul>
<p>I have to also assume your file may be very big, so readi... | 0 | 2009-12-16T14:28:34Z | [
"python",
"file",
"list",
"input"
] |
Problems installing MySQL-python-1.2.3c1 on Mac Snow Leopard | 1,907,540 | <p>Hi All
I am having a problem installing the Python MySQL connector (MySQL-python-1.2.3c1) on my Mac OSX Snow Leopard.</p>
<p><strong>System State</strong></p>
<p>I have manually compiled an installed:
<strong>mysql-5.1.41</strong></p>
<p>This seems to work fine, as I can create and query a database from the comma... | 2 | 2009-12-15T13:41:38Z | 1,907,747 | <p>What does </p>
<pre><code>otool -L /Users/username/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
</code></pre>
<p>report?</p>
| 1 | 2009-12-15T14:15:26Z | [
"python",
"mysql",
"osx",
"osx-snow-leopard",
"compilation"
] |
Problems installing MySQL-python-1.2.3c1 on Mac Snow Leopard | 1,907,540 | <p>Hi All
I am having a problem installing the Python MySQL connector (MySQL-python-1.2.3c1) on my Mac OSX Snow Leopard.</p>
<p><strong>System State</strong></p>
<p>I have manually compiled an installed:
<strong>mysql-5.1.41</strong></p>
<p>This seems to work fine, as I can create and query a database from the comma... | 2 | 2009-12-15T13:41:38Z | 1,908,068 | <p>First, I would suggest using the MySQL binaries for MacOS X 10.5 64-bit (x86_64). The tar ball works on MacOS X 10.6.</p>
<p>You said you used ARCHFLAGS.. however, try it again like this:</p>
<pre><code>shell> ARCHFLAGS="-arch x86_64" python setup.py build
shell> sudo python setup.py install
</code></pre>
<... | 1 | 2009-12-15T15:06:10Z | [
"python",
"mysql",
"osx",
"osx-snow-leopard",
"compilation"
] |
C,Python - different behaviour of the modulo (%) operation | 1,907,565 | <p>I have found that the same mod operation produces different results depending on what language is being used.</p>
<p>In Python:</p>
<pre><code>-1 % 10
</code></pre>
<p>produces <strong>9</strong></p>
<p>In C it produces <strong>-1</strong> !</p>
<p>1) Which one is the right modulo? <br>
2) How to make mod opera... | 40 | 2009-12-15T13:46:07Z | 1,907,584 | <p>Both answers are correct since <code>-1 modulo 10</code> is the same as <code>9 modulo 10</code>. </p>
<pre><code>r = (a mod m)
a = n*q + r
</code></pre>
<p>You can be sure that <code>|r| < |n|</code>, but not what the value of <code>r</code> is. There are 2 answers, negative and positive.</p>
<p><hr></p>
<... | 5 | 2009-12-15T13:48:05Z | [
"python",
"c",
"math"
] |
C,Python - different behaviour of the modulo (%) operation | 1,907,565 | <p>I have found that the same mod operation produces different results depending on what language is being used.</p>
<p>In Python:</p>
<pre><code>-1 % 10
</code></pre>
<p>produces <strong>9</strong></p>
<p>In C it produces <strong>-1</strong> !</p>
<p>1) Which one is the right modulo? <br>
2) How to make mod opera... | 40 | 2009-12-15T13:46:07Z | 1,907,585 | <ol>
<li>Both variants are correct, however in mathematics (number theory in particular), Python's <a href="http://en.wikipedia.org/wiki/Modulo%5Foperation">modulo</a> is most commonly used.</li>
<li>In C, you do <code>((n % M) + M) % M</code> to get the same result as in Python. E. g. <code>((-1 % 10) + 10) % 10</code... | 46 | 2009-12-15T13:48:13Z | [
"python",
"c",
"math"
] |
C,Python - different behaviour of the modulo (%) operation | 1,907,565 | <p>I have found that the same mod operation produces different results depending on what language is being used.</p>
<p>In Python:</p>
<pre><code>-1 % 10
</code></pre>
<p>produces <strong>9</strong></p>
<p>In C it produces <strong>-1</strong> !</p>
<p>1) Which one is the right modulo? <br>
2) How to make mod opera... | 40 | 2009-12-15T13:46:07Z | 1,907,723 | <p>Python has a "true" modulo operation, while C has a <em>remainder</em> operation.</p>
<p>It has a direct relation with how the negative integer division is handled, i.e. rounded towards 0 or minus infinite. Python rounds towards minus infinite and C(99) towards 0, but in both languages <code>(n/m)*m + n%m == n</cod... | 23 | 2009-12-15T14:11:20Z | [
"python",
"c",
"math"
] |
C,Python - different behaviour of the modulo (%) operation | 1,907,565 | <p>I have found that the same mod operation produces different results depending on what language is being used.</p>
<p>In Python:</p>
<pre><code>-1 % 10
</code></pre>
<p>produces <strong>9</strong></p>
<p>In C it produces <strong>-1</strong> !</p>
<p>1) Which one is the right modulo? <br>
2) How to make mod opera... | 40 | 2009-12-15T13:46:07Z | 1,907,889 | <p>In C89/90 the behavior of division operator and remainder operator with negative operands is <em>implementation-defined</em>, meaning that depending on the implementation you can get either behavior. It is just required that the operators agree with each other: from <code>a / b = q</code> and <code>a % b = r</code> ... | 13 | 2009-12-15T14:38:36Z | [
"python",
"c",
"math"
] |
Examples of using Doctests in Django in an Agile / BDD way | 1,907,610 | <p>I'm interested in learning how to Doctests and Unit tests in a more Agile / BDD way.
I've found a few tutorials that seem reasonable, but they are just thumbnails.
What I would really like to see is the source code of some Django projects that were developed BDD style.</p>
<p>The things I'm unclear about are how do... | 6 | 2009-12-15T13:51:49Z | 1,907,854 | <p>The <a href="http://pypi.python.org/pypi/zope.testbrowser" rel="nofollow">zope.testbrowser</a> package might be useful in your doctests, since you want to analyse the rendered HTML answer of your production server.</p>
| 0 | 2009-12-15T14:33:34Z | [
"python",
"django",
"agile",
"doctest"
] |
Examples of using Doctests in Django in an Agile / BDD way | 1,907,610 | <p>I'm interested in learning how to Doctests and Unit tests in a more Agile / BDD way.
I've found a few tutorials that seem reasonable, but they are just thumbnails.
What I would really like to see is the source code of some Django projects that were developed BDD style.</p>
<p>The things I'm unclear about are how do... | 6 | 2009-12-15T13:51:49Z | 1,907,932 | <p>The way your view is written, it would be hard to test. You'd have to scrape the html to see if the content you want is present, and then you're testing more than you need to. Better would be to rewrite your view to make it easier to test. Start by parameterizing your template name, so you can create a simple tes... | 1 | 2009-12-15T14:46:02Z | [
"python",
"django",
"agile",
"doctest"
] |
Examples of using Doctests in Django in an Agile / BDD way | 1,907,610 | <p>I'm interested in learning how to Doctests and Unit tests in a more Agile / BDD way.
I've found a few tutorials that seem reasonable, but they are just thumbnails.
What I would really like to see is the source code of some Django projects that were developed BDD style.</p>
<p>The things I'm unclear about are how do... | 6 | 2009-12-15T13:51:49Z | 1,917,588 | <p>I've asked myself the same question before. I've found doctests to be of limited utility for things like views, model methods and managers because</p>
<ol>
<li>You need to be able to setup and teardown a test data set to actually use for testing</li>
<li>Views need to take a request object. In a doctest, where does... | 3 | 2009-12-16T20:48:07Z | [
"python",
"django",
"agile",
"doctest"
] |
Examples of using Doctests in Django in an Agile / BDD way | 1,907,610 | <p>I'm interested in learning how to Doctests and Unit tests in a more Agile / BDD way.
I've found a few tutorials that seem reasonable, but they are just thumbnails.
What I would really like to see is the source code of some Django projects that were developed BDD style.</p>
<p>The things I'm unclear about are how do... | 6 | 2009-12-15T13:51:49Z | 2,018,524 | <p>You can use the <a href="http://docs.djangoproject.com/en/dev/topics/testing/#module-django.test.client" rel="nofollow">django testclient</a> and test the context variables that get set:</p>
<pre><code>>>> response = client.get('/foo/')
>>> response.context['name']
'Arthur'
</code></pre>
<p>You c... | 1 | 2010-01-07T06:02:07Z | [
"python",
"django",
"agile",
"doctest"
] |
python raw_input def input problem | 1,907,647 | <p>I am only going to post the portion where the problem is at, the program has no error (all the codes are valid except for this <code>raw_input</code> problem)</p>
<p>I tested with <code>search_function(1)</code> and etc and it worked.</p>
<p>But if I do this while loop, it doesn't print anything.
Example output:<... | 1 | 2009-12-15T13:57:20Z | 1,907,661 | <p><code>raw_input()</code> returns string, while your code expects integer. Use <code>search_function(int(x))</code> or change conditions to compare with strings.</p>
| 2 | 2009-12-15T14:00:51Z | [
"python",
"input"
] |
python raw_input def input problem | 1,907,647 | <p>I am only going to post the portion where the problem is at, the program has no error (all the codes are valid except for this <code>raw_input</code> problem)</p>
<p>I tested with <code>search_function(1)</code> and etc and it worked.</p>
<p>But if I do this while loop, it doesn't print anything.
Example output:<... | 1 | 2009-12-15T13:57:20Z | 1,907,752 | <p>Test for <code>x == 'STOP'</code> first and <code>break</code> if True, else cast to int and call <code>search_function</code>:</p>
<pre><code>while True:
x = raw_input("Enter a number to print specific table, or STOP to quit: ")
if x == 'STOP':
break
search_function(int(x))
</code></pre>
| 1 | 2009-12-15T14:16:52Z | [
"python",
"input"
] |
Update Facebook Page's status using pyfacebook | 1,907,662 | <p>I am attempting to add functionality to my Django app: when a new post is approved, I want to update the corresponding Facebook Page's status with a message and a link to the post automatically. Basic status update.</p>
<p>I have downloaded and installed <a href="http://github.com/sciyoshi/pyfacebook/blob/master/f... | 2 | 2009-12-15T14:00:59Z | 1,907,729 | <p>In the definition of <code>login</code>, particularly in the docstring, it appears as though the intended behavior is to open up a browser in order to have you log in that way.</p>
<pre><code>def login(self, popup=False):
"""Open a web browser telling the user to login to Facebook."""
import webbrowser
... | 2 | 2009-12-15T14:12:40Z | [
"python",
"django",
"facebook",
"pyfacebook"
] |
Update Facebook Page's status using pyfacebook | 1,907,662 | <p>I am attempting to add functionality to my Django app: when a new post is approved, I want to update the corresponding Facebook Page's status with a message and a link to the post automatically. Basic status update.</p>
<p>I have downloaded and installed <a href="http://github.com/sciyoshi/pyfacebook/blob/master/f... | 2 | 2009-12-15T14:00:59Z | 4,580,102 | <p>If you want to login to your facebook profile page I have managed to do it with this script:</p>
<p>Save this file as <strong>fb_login.py</strong> and in the same folder create a file <strong>fb_test.html</strong></p>
<p>I successfully logged in as you can prove by viewing on your browser the fb_test.html or searc... | 0 | 2011-01-02T19:33:23Z | [
"python",
"django",
"facebook",
"pyfacebook"
] |
Framework for building visually rich desktop applications? | 1,907,736 | <p>I've started building an app with Flex/Air but am getting sick of it's clunkyness.</p>
<p>The app that I'm building has similar behaviour to Prezi (www.prezi.com) but in a completely different field.</p>
<p>I'm looking for something on the desktop which has flex like capabilities, such as drawing vectors then zoom... | 0 | 2009-12-15T14:13:29Z | 1,907,910 | <p>Qt (Python bindings: <a href="http://www.riverbankcomputing.co.uk/software/pyqt/intro" rel="nofollow">PyQt</a>) is a flexible and mature framework that can certainly do that (take a look at QGraphicsView and QGraphicsScene for example). </p>
<p>You'll have to code most of it 'by hand' though (the designer is good ... | 3 | 2009-12-15T14:42:14Z | [
"python",
"vector",
"svg"
] |
Framework for building visually rich desktop applications? | 1,907,736 | <p>I've started building an app with Flex/Air but am getting sick of it's clunkyness.</p>
<p>The app that I'm building has similar behaviour to Prezi (www.prezi.com) but in a completely different field.</p>
<p>I'm looking for something on the desktop which has flex like capabilities, such as drawing vectors then zoom... | 0 | 2009-12-15T14:13:29Z | 1,907,972 | <p>If you have any .NET experience I would recommend Silverlight. I have worked with it in the academic setting and it has impressed me very much. Some of the examples are pretty mind blowing, for the web applications at least. I also know they did focus on making silverlight into exactly what your question asks, a ... | 0 | 2009-12-15T14:53:31Z | [
"python",
"vector",
"svg"
] |
From Sax to Dom with DTD (python) | 1,907,740 | <p>I need a validated DomTree with DTD (to use <code>getElementById</code>).
Validating and Parsing works, but the dom does't work properly:</p>
<pre><code>from xml.dom import minidom
from xml.dom.pulldom import SAX2DOM
from lxml import etree
import lxml.sax
from StringIO import StringIO
data_string = """\
<?xml ... | 1 | 2009-12-15T14:14:05Z | 1,908,320 | <p>As far as I know: SAX DTD events are not handled by the ContentHandler, but by the <a href="http://docs.python.org/library/xml.sax.reader.html?highlight=setproperty#xml.sax.xmlreader.XMLReader.setDTDHandler" rel="nofollow">DTDHandler</a>, which is a property you can set on the sax parser (XMLReader). This means that... | 1 | 2009-12-15T15:47:13Z | [
"python",
"dom",
"dtd",
"sax"
] |
Integrate Python app into PHP site | 1,907,782 | <p>This might sound really crazy, but still...</p>
<p>For our revamped project site, we want to integrate Trac (as code browser, developer wiki and issue tracker) into the site design. That is, of course, difficult, since Trac is written in Python and our site in PHP. Does anybody here know a way how to integrate a he... | 4 | 2009-12-15T14:21:15Z | 1,907,850 | <p>The best option probably is to (re)write the header and footer using python.</p>
<p>If the header and footer are relatively static you can also generate them once using php (or once every x minutes) and include them from the filesystem. (You probably already thought about this and dismissed the idea because your si... | 1 | 2009-12-15T14:33:10Z | [
"php",
"python",
"integration",
"trac"
] |
Integrate Python app into PHP site | 1,907,782 | <p>This might sound really crazy, but still...</p>
<p>For our revamped project site, we want to integrate Trac (as code browser, developer wiki and issue tracker) into the site design. That is, of course, difficult, since Trac is written in Python and our site in PHP. Does anybody here know a way how to integrate a he... | 4 | 2009-12-15T14:21:15Z | 1,909,017 | <p>Abstraction is your friend.</p>
<p>Isolate the raw HTML from your PHP in the header and footer in a simple templating language, if possible, and write Python and PHP interfaces to your templating language. Or, reuse the work that other people have done. <a href="http://en.wikipedia.org/wiki/Template%5Fengine%5F%2... | 1 | 2009-12-15T17:24:12Z | [
"php",
"python",
"integration",
"trac"
] |
Integrate Python app into PHP site | 1,907,782 | <p>This might sound really crazy, but still...</p>
<p>For our revamped project site, we want to integrate Trac (as code browser, developer wiki and issue tracker) into the site design. That is, of course, difficult, since Trac is written in Python and our site in PHP. Does anybody here know a way how to integrate a he... | 4 | 2009-12-15T14:21:15Z | 1,909,272 | <p>Your Python code will have access to your users' cookies. A template would be best, but if you don't have one available (or the header/footer are trivially small, or whatever), you can simply port the PHP header and footer code to Python, using the cookies that are already there to query the database or whatever you... | 0 | 2009-12-15T18:07:04Z | [
"php",
"python",
"integration",
"trac"
] |
Higher-performance method do this type of insert from python? | 1,907,911 | <p>Given two arrays <code>hashes</code> and <code>table</code>, for each value in <code>hashes</code> I want to store the position of the element at the element's value's offset in the array <code>table</code>. Here is the naïve algorithm: </p>
<pre><code>def insert_n(table,hashes):
for x in xrange(len(hashes)):
... | 1 | 2009-12-15T14:42:28Z | 1,909,669 | <p>This is fast and simple (assuming table and hashes are numpy.uint32 arrays):</p>
<pre><code>table[hashes] = numpy.arange(len(hashes), dtype=numpy.uint32)
</code></pre>
<p>You may want to compare the speed with this:</p>
<pre><code>table[hashes] = xrange(len(hashes))
</code></pre>
<p>By the way, <code>numpy.inser... | 2 | 2009-12-15T19:12:23Z | [
"python",
"algorithm",
"performance",
"benchmarking"
] |
Encoding utf-8 to base64 with accents | 1,908,035 | <p>I have some data like this:</p>
<pre><code>data1 = ['Agos', '30490349304']
data2 = ['Desir\xc3\xa9','9839483948']
</code></pre>
<p>I'm using an API that expects the data encoded in base64, so what I do is:</p>
<pre><code>data = data1
string = base64.b64encode("Hi, %s! Your code is %s" % (data[0], data[0]))
myXMLR... | 0 | 2009-12-15T15:02:17Z | 1,908,102 | <p>First make sure you're not confused about encodings, etc. Read, for example, <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow">this</a>.</p>
<p>Then notice that the main problem isn't with the base64 encoding, but with the fact that you're trying to put byte string (normal string in Pytho... | 1 | 2009-12-15T15:12:12Z | [
"python",
"encoding",
"utf-8",
"ascii",
"base64"
] |
Encoding utf-8 to base64 with accents | 1,908,035 | <p>I have some data like this:</p>
<pre><code>data1 = ['Agos', '30490349304']
data2 = ['Desir\xc3\xa9','9839483948']
</code></pre>
<p>I'm using an API that expects the data encoded in base64, so what I do is:</p>
<pre><code>data = data1
string = base64.b64encode("Hi, %s! Your code is %s" % (data[0], data[0]))
myXMLR... | 0 | 2009-12-15T15:02:17Z | 1,908,114 | <pre><code>base64.b64encode("Hi, %s! Your code is %s" % (data[0].decode('utf8').encode('latin1'), data[0]))
</code></pre>
| 1 | 2009-12-15T15:13:53Z | [
"python",
"encoding",
"utf-8",
"ascii",
"base64"
] |
Encoding utf-8 to base64 with accents | 1,908,035 | <p>I have some data like this:</p>
<pre><code>data1 = ['Agos', '30490349304']
data2 = ['Desir\xc3\xa9','9839483948']
</code></pre>
<p>I'm using an API that expects the data encoded in base64, so what I do is:</p>
<pre><code>data = data1
string = base64.b64encode("Hi, %s! Your code is %s" % (data[0], data[0]))
myXMLR... | 0 | 2009-12-15T15:02:17Z | 1,908,128 | <p>This seem to work:</p>
<pre><code>...
data = data2
base64.b64encode("Hi, %s! Your code is %s" % (data[0], data[0]))
# => 'SGksIERlc2lyw6khIFlvdXIgY29kZSBpcyBEZXNpcsOp'
# I can't test the XMLRPC parts, so this is just a hint ..
for_the_wire = base64.b64encode("Hi, %s! Your code is %s" % (data[0], data[0]))
lati... | 0 | 2009-12-15T15:15:16Z | [
"python",
"encoding",
"utf-8",
"ascii",
"base64"
] |
Improve code: test for key in dict and store in datastore | 1,908,104 | <p>Hey, I'm fairly new to python I have this piece of code which stores the birth info to the datastore in Google App Engine. The code works but is it the correct way to do it? Is there a simpler way to do it, to make sure that the key exists before storing it in datastore?</p>
<pre><code>def store_birthinfo(self, use... | 0 | 2009-12-15T15:12:41Z | 1,908,130 | <pre><code>def store_birthinfo(self, user, birthday):
"""
Store birthinfo
"""
birthinfo = BirthInfo(user=user, **birthday)
birthinfo.put()
</code></pre>
<p>see the docs on <a href="http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow">unpacking argument lists</a>.</p>... | 2 | 2009-12-15T15:16:05Z | [
"python",
"google-app-engine"
] |
Improve code: test for key in dict and store in datastore | 1,908,104 | <p>Hey, I'm fairly new to python I have this piece of code which stores the birth info to the datastore in Google App Engine. The code works but is it the correct way to do it? Is there a simpler way to do it, to make sure that the key exists before storing it in datastore?</p>
<pre><code>def store_birthinfo(self, use... | 0 | 2009-12-15T15:12:41Z | 1,908,203 | <p>ÊÉıu's answer is the shortest, though it has slightly different semantics than yours, in that yours will provide an explicit empty string argument if the key is missing from the dictionary, while ÊÉıu's will omit the keyword argument altogether. </p>
<p>For the sake of completeness, there's a simpler way to d... | 1 | 2009-12-15T15:30:14Z | [
"python",
"google-app-engine"
] |
Improve code: test for key in dict and store in datastore | 1,908,104 | <p>Hey, I'm fairly new to python I have this piece of code which stores the birth info to the datastore in Google App Engine. The code works but is it the correct way to do it? Is there a simpler way to do it, to make sure that the key exists before storing it in datastore?</p>
<pre><code>def store_birthinfo(self, use... | 0 | 2009-12-15T15:12:41Z | 1,908,223 | <p>A problem might be if your variable 'birthday' contains keys that the class BirthInfo doesn't expect. A more solid solution might be this which also gives you the clear insight into if blanks ones become None or empty string:</p>
<pre><code>def store_birthinfo(self, user, birthday):
data = dict(name='', date='', ... | 0 | 2009-12-15T15:33:15Z | [
"python",
"google-app-engine"
] |
Improve code: test for key in dict and store in datastore | 1,908,104 | <p>Hey, I'm fairly new to python I have this piece of code which stores the birth info to the datastore in Google App Engine. The code works but is it the correct way to do it? Is there a simpler way to do it, to make sure that the key exists before storing it in datastore?</p>
<pre><code>def store_birthinfo(self, use... | 0 | 2009-12-15T15:12:41Z | 1,908,244 | <p>You can create a default dictionary and then update the target dictionary as in</p>
<pre><code>def store_birthinfo(self, user, birthday):
"""Store birthinfo"""
birth_defaults = { 'name' : '',
'date' : '',
'place' : '',
'country' : ''}
birth_defau... | 1 | 2009-12-15T15:36:47Z | [
"python",
"google-app-engine"
] |
Improve code: test for key in dict and store in datastore | 1,908,104 | <p>Hey, I'm fairly new to python I have this piece of code which stores the birth info to the datastore in Google App Engine. The code works but is it the correct way to do it? Is there a simpler way to do it, to make sure that the key exists before storing it in datastore?</p>
<pre><code>def store_birthinfo(self, use... | 0 | 2009-12-15T15:12:41Z | 1,908,967 | <p>Building on Peter Bengtsson's post, you could also define the list of relevant keys, and leave data as an empty <code>{}</code> until the loop populates it.</p>
<pre><code>def store_birthinfo(self, user, birthday):
data = {}
for key in 'date', 'place', 'country':
data[key] = birthday.get(key, '')
... | 0 | 2009-12-15T17:13:50Z | [
"python",
"google-app-engine"
] |
In there something similar to Java's Thread.yield() in Python? Does that even make sense? | 1,908,206 | <p>I want to tell my Python threads to yield, and so avoid hogging the CPU unnecessarily. In Java, you could do that using the <code>Thread.yield()</code> function. I don't think there is something similar in Python, so I have been using <code>time.sleep(t)</code> where <code>t = 0.00001</code>. For <code>t=0</code> th... | 7 | 2009-12-15T15:30:28Z | 1,908,252 | <p>Dup of: <a href="http://stackoverflow.com/questions/787803/how-does-a-threading-thread-yield-the-rest-of-its-quantum-in-python">How does a threading.Thread yield the rest of its quantum in Python?</a>.</p>
<pre><code>time.sleep(0)
</code></pre>
| 10 | 2009-12-15T15:38:13Z | [
"python",
"multithreading",
"sleep",
"yield"
] |
In there something similar to Java's Thread.yield() in Python? Does that even make sense? | 1,908,206 | <p>I want to tell my Python threads to yield, and so avoid hogging the CPU unnecessarily. In Java, you could do that using the <code>Thread.yield()</code> function. I don't think there is something similar in Python, so I have been using <code>time.sleep(t)</code> where <code>t = 0.00001</code>. For <code>t=0</code> th... | 7 | 2009-12-15T15:30:28Z | 1,908,305 | <p>The interpreter will switch from one thread to another periodically anyway without your intervention - you don't need to tell the system not to 'hog' a thread.</p>
<p>However, under normal circumstances, only one Python thread is executing at any one time. (Exceptions tend to revolve around times when threads are w... | 1 | 2009-12-15T15:43:41Z | [
"python",
"multithreading",
"sleep",
"yield"
] |
In there something similar to Java's Thread.yield() in Python? Does that even make sense? | 1,908,206 | <p>I want to tell my Python threads to yield, and so avoid hogging the CPU unnecessarily. In Java, you could do that using the <code>Thread.yield()</code> function. I don't think there is something similar in Python, so I have been using <code>time.sleep(t)</code> where <code>t = 0.00001</code>. For <code>t=0</code> th... | 7 | 2009-12-15T15:30:28Z | 38,280,120 | <p>Thread.yield() is missing from python because perhaps it has been forgotten, or the designer thought that all synchronization and interprocess communication issues are solvable without Thread.yield().</p>
<p>I'd use Thread.yield() for the following issue:</p>
<p>E.g. there is a job queue and there are 2 worker thr... | 0 | 2016-07-09T09:00:19Z | [
"python",
"multithreading",
"sleep",
"yield"
] |
Best way to add python scripting into QT application? | 1,908,269 | <p>I have a QT 4.6 application (C++ language) and i need to add python scripting to it on windows platform. Unfortunately, i never embed python before, and it seems to be a lot of different ways to do so. Can anyone share his wisdom and point me into some articles/documentation i can read to perform a specified task in... | 5 | 2009-12-15T15:39:58Z | 1,908,651 | <p><strong>Edit:</strong></p>
<p>You can use PythonQt (not PyQt) that allow you to use Python with Qt. I think this is what you are searching for.</p>
<p>Here a documentation on the official website: <a href="http://doc.qt.digia.com/qq/qq23-pythonqt.html" rel="nofollow">http://doc.qt.digia.com/qq/qq23-pythonqt.html</... | 5 | 2009-12-15T16:30:52Z | [
"c++",
"python",
"qt"
] |
Best way to add python scripting into QT application? | 1,908,269 | <p>I have a QT 4.6 application (C++ language) and i need to add python scripting to it on windows platform. Unfortunately, i never embed python before, and it seems to be a lot of different ways to do so. Can anyone share his wisdom and point me into some articles/documentation i can read to perform a specified task in... | 5 | 2009-12-15T15:39:58Z | 1,908,788 | <p>You should take a look at <a href="http://pythonqt.sourceforge.net/" rel="nofollow">PythonQt</a>. From the homepage:</p>
<blockquote>
<p>PythonQt is a dynamic <a href="http://www.python.org" rel="nofollow">Python</a>
binding for <a href="http://qt.nokia.com/" rel="nofollow">Qt</a>. It offers
an easy way to em... | 5 | 2009-12-15T16:51:37Z | [
"c++",
"python",
"qt"
] |
How to combine multiple images fast for page views counter | 1,908,334 | <p>How can I combine multiple images, such as base image with logo and number of digits images to display graphical counter with pageviews count, updated dynamically?</p>
<p>It should be very fast, with thousands of renders per second. User should see counter image without Javascript and with single <code>img</code> t... | 0 | 2009-12-15T15:49:05Z | 1,908,385 | <p>Precompute for the given background the image of a single digit (for each digit 0 ... 10) at each digit position.
Then to create arbitrary number you only have to paste the correct images next to eachother, but you won't have to do any alpha blending. Therefore this must be more efficient.</p>
<p>Also, if certain p... | 2 | 2009-12-15T15:55:12Z | [
"python",
"python-imaging-library",
"counter"
] |
How to combine multiple images fast for page views counter | 1,908,334 | <p>How can I combine multiple images, such as base image with logo and number of digits images to display graphical counter with pageviews count, updated dynamically?</p>
<p>It should be very fast, with thousands of renders per second. User should see counter image without Javascript and with single <code>img</code> t... | 0 | 2009-12-15T15:49:05Z | 1,908,428 | <p>If you really need to handle thousands "renders" per second I would not suggest to generate the images on the fly. How about precomputing n images where n is the expected (you might want to be generous here) count you have to handle?</p>
<p>I know you state that you don't want to use javascript and you only want on... | 0 | 2009-12-15T16:00:08Z | [
"python",
"python-imaging-library",
"counter"
] |
How to combine multiple images fast for page views counter | 1,908,334 | <p>How can I combine multiple images, such as base image with logo and number of digits images to display graphical counter with pageviews count, updated dynamically?</p>
<p>It should be very fast, with thousands of renders per second. User should see counter image without Javascript and with single <code>img</code> t... | 0 | 2009-12-15T15:49:05Z | 1,908,453 | <p>Since the background is uniform in your example, render the string "0123456789" and use <a href="http://www.alistapart.com/articles/sprites/" rel="nofollow">CSS sprites</a> to build the counter.</p>
| 0 | 2009-12-15T16:02:53Z | [
"python",
"python-imaging-library",
"counter"
] |
Parsing XML to a hash table | 1,908,410 | <p>I have an XML file in the following format:</p>
<pre><code><doc>
<id name="X">
<type name="A">
<min val="100" id="80"/>
<max val="200" id="90"/>
</type>
<type name="B">
<min val="100" id="20"/>
<max val="20" id="90"/>
</type>
<... | 4 | 2009-12-15T15:57:26Z | 1,908,436 | <p>I would recommend using the <a href="http://docs.python.org/library/xml.dom.minidom.html" rel="nofollow">minidom</a> library.</p>
<p>The docs are pretty good so you should be up and running in no time.</p>
<p>Dan.</p>
| 2 | 2009-12-15T16:00:45Z | [
"python",
"xml",
"dom"
] |
Parsing XML to a hash table | 1,908,410 | <p>I have an XML file in the following format:</p>
<pre><code><doc>
<id name="X">
<type name="A">
<min val="100" id="80"/>
<max val="200" id="90"/>
</type>
<type name="B">
<min val="100" id="20"/>
<max val="20" id="90"/>
</type>
<... | 4 | 2009-12-15T15:57:26Z | 1,908,451 | <p>Why not try something like the <a href="http://pyxml.sourceforge.net/topics/" rel="nofollow">PyXml</a> library. They have lots of documentation and tutorials.</p>
| 0 | 2009-12-15T16:02:45Z | [
"python",
"xml",
"dom"
] |
Parsing XML to a hash table | 1,908,410 | <p>I have an XML file in the following format:</p>
<pre><code><doc>
<id name="X">
<type name="A">
<min val="100" id="80"/>
<max val="200" id="90"/>
</type>
<type name="B">
<min val="100" id="20"/>
<max val="20" id="90"/>
</type>
<... | 4 | 2009-12-15T15:57:26Z | 1,908,464 | <p>Another XML parsing library: <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">http://www.crummy.com/software/BeautifulSoup/</a></p>
<ul>
<li>Parsing XML documentation starts here: <a href="http://www.crummy.com/software/BeautifulSoup/documentation.html#Parsing%20XML" rel="nofollow">http://www.... | 1 | 2009-12-15T16:04:45Z | [
"python",
"xml",
"dom"
] |
Parsing XML to a hash table | 1,908,410 | <p>I have an XML file in the following format:</p>
<pre><code><doc>
<id name="X">
<type name="A">
<min val="100" id="80"/>
<max val="200" id="90"/>
</type>
<type name="B">
<min val="100" id="20"/>
<max val="20" id="90"/>
</type>
<... | 4 | 2009-12-15T15:57:26Z | 1,908,695 | <p>As others have stated <a href="http://docs.python.org/library/xml.dom.minidom.html" rel="nofollow">minidom</a> is the way to go here. You open (and parse) the file, while going through the nodes you check if its relevant and should be read. That way, you also know if you want to read the child nodes.</p>
<p>Threw t... | 2 | 2009-12-15T16:38:07Z | [
"python",
"xml",
"dom"
] |
Parsing XML to a hash table | 1,908,410 | <p>I have an XML file in the following format:</p>
<pre><code><doc>
<id name="X">
<type name="A">
<min val="100" id="80"/>
<max val="200" id="90"/>
</type>
<type name="B">
<min val="100" id="20"/>
<max val="20" id="90"/>
</type>
<... | 4 | 2009-12-15T15:57:26Z | 1,908,987 | <p>I disagree with the suggestion in other answers to use minidom -- that's a so-so Python adaptation of a standard originally conceived for other languages, usable but not a great fit. The recommended approach in modern Python is <a href="http://docs.python.org/library/xml.etree.elementtree.html">ElementTree</a>.</p>
... | 12 | 2009-12-15T17:18:26Z | [
"python",
"xml",
"dom"
] |
Parsing XML to a hash table | 1,908,410 | <p>I have an XML file in the following format:</p>
<pre><code><doc>
<id name="X">
<type name="A">
<min val="100" id="80"/>
<max val="200" id="90"/>
</type>
<type name="B">
<min val="100" id="20"/>
<max val="20" id="90"/>
</type>
<... | 4 | 2009-12-15T15:57:26Z | 1,910,502 | <p>Do not reinvent the wheel. Use Amara toolkit.
Variable names are just keys in a dictionary anyway.
<a href="http://www.xml3k.org/Amara" rel="nofollow">http://www.xml3k.org/Amara</a></p>
| 3 | 2009-12-15T21:25:13Z | [
"python",
"xml",
"dom"
] |
how to use ffmpeg | 1,908,411 | <p>im trying to extract frames from a video .. and i picked ffmpeg ( tell me if you know something better ) for this task<br>
i downloaded it's source .. and i don't know how to use it ?? how do i compile it ??<br>
what is the recommended language for it ?? i know python and C++ <br>
please note that i use windows vis... | 5 | 2009-12-15T15:57:38Z | 1,908,534 | <p>If you only want <em>use</em> ffmpeg you should just get a build and not the source itself. </p>
<p>To extract a frame from a video use the following command line:</p>
<pre><code>ffmpeg -i input.avi -r 1 -f image2 -s 120x96 images%05d.png
</code></pre>
<p>Where input.avi is your video, 120x96 the dimension of the... | 1 | 2009-12-15T16:13:10Z | [
"c++",
"python",
"ffmpeg"
] |
how to use ffmpeg | 1,908,411 | <p>im trying to extract frames from a video .. and i picked ffmpeg ( tell me if you know something better ) for this task<br>
i downloaded it's source .. and i don't know how to use it ?? how do i compile it ??<br>
what is the recommended language for it ?? i know python and C++ <br>
please note that i use windows vis... | 5 | 2009-12-15T15:57:38Z | 1,908,601 | <p>If you just want to extract the frames from a video and save them to file, you can just use ffmpeg at the command line:</p>
<pre><code>ffmpeg -i video.avi image%d.jpg
</code></pre>
<p>For this method, you do not need to build ffmpeg as there should be a windows binary available for download.</p>
<p>If you are wan... | 1 | 2009-12-15T16:22:44Z | [
"c++",
"python",
"ffmpeg"
] |
how to use ffmpeg | 1,908,411 | <p>im trying to extract frames from a video .. and i picked ffmpeg ( tell me if you know something better ) for this task<br>
i downloaded it's source .. and i don't know how to use it ?? how do i compile it ??<br>
what is the recommended language for it ?? i know python and C++ <br>
please note that i use windows vis... | 5 | 2009-12-15T15:57:38Z | 2,641,471 | <p>If you know C++, you can modify sample from article <a href="http://unick-soft.ru/article.php?id=14" rel="nofollow">using ffmpeg</a>.</p>
| 3 | 2010-04-14T22:19:40Z | [
"c++",
"python",
"ffmpeg"
] |
Google Alerts web API for Python? | 1,908,653 | <p>Google web APIs have a <a href="http://code.google.com/p/gdata-python-client/" rel="nofollow">Python library</a>. <a href="http://www.google.com/alerts" rel="nofollow">Google Alerts</a> has an email and an RSS feed.</p>
<p>Does anyone know of an automated way to add Google Alerts through a web API in Python? That i... | 4 | 2009-12-15T16:31:17Z | 13,122,328 | <p>There is galerts <a href="http://pypi.python.org/pypi/galerts" rel="nofollow">http://pypi.python.org/pypi/galerts</a>.</p>
<p>It has the ability to add and manage alerts and subscriptions directly from python.</p>
| 3 | 2012-10-29T13:10:47Z | [
"python",
"web-api",
"google-alerts"
] |
Storing times in Python - Best format? | 1,908,670 | <p>When storing a time in Python (in my case in ZODB, but applies to any DB), what format (epoch, datetime etc) do you use and why?</p>
| 0 | 2009-12-15T16:33:37Z | 1,908,812 | <p>The <a href="http://docs.python.org/library/datetime.html" rel="nofollow">datetime</a> module has the standard types for modern Python handling of dates and times, and I use it because I like standards (I also think it's well designed); I typically also have timezone information via <a href="http://pytz.sourceforge.... | 5 | 2009-12-15T16:55:03Z | [
"python",
"datetime"
] |
Storing times in Python - Best format? | 1,908,670 | <p>When storing a time in Python (in my case in ZODB, but applies to any DB), what format (epoch, datetime etc) do you use and why?</p>
| 0 | 2009-12-15T16:33:37Z | 1,908,838 | <p>If the database has a native date-time format, I try to use that even if it involves encoding and decoding. Even if this is not 100% standard such as SQLITE, I would still use the date and time adaptors described near the bottom of the <a href="http://docs.python.org/library/sqlite3.html">SQLITE3 help page</a>.</p>
... | 5 | 2009-12-15T16:57:00Z | [
"python",
"datetime"
] |
Storing times in Python - Best format? | 1,908,670 | <p>When storing a time in Python (in my case in ZODB, but applies to any DB), what format (epoch, datetime etc) do you use and why?</p>
| 0 | 2009-12-15T16:33:37Z | 1,920,099 | <p>Seconds since epoch is the most compact and portable format for storing time data. Native DATETIME format in MySQL, for example, takes 8 bytes instead of 4 for TIMESTAMP (seconds since epoch). You'd also avoid timezone issues if you need to get the time from clients in multiple geographic locations. Logical operatio... | 0 | 2009-12-17T07:46:45Z | [
"python",
"datetime"
] |
How to do this GROUP BY query in Django's ORM with annotate and aggregate | 1,908,741 | <p>I don't really have groked how to translate <code>GROUP BY</code> and <code>HAVING</code> to Django's <code>QuerySet.annotate</code> and <code>QuerySet.aggregate</code>. I'm trying to translate this SQL query into ORM speak</p>
<pre><code>SELECT EXTRACT(year FROM pub_date) as year, EXTRACT(month from pub_date) as m... | 5 | 2009-12-15T16:43:37Z | 1,909,277 | <p>I think to do it in one query you might have to have month and year as separate fields...</p>
<pre><code>Article.objects.values('pub_date').annotate(article_count=Count('title'))
</code></pre>
<p>That would <code>group by</code> by pub_date. But there is no way I can think of to do the equivalent of the <code>extr... | 14 | 2009-12-15T18:08:11Z | [
"python",
"django",
"orm",
"group-by"
] |
How to do this GROUP BY query in Django's ORM with annotate and aggregate | 1,908,741 | <p>I don't really have groked how to translate <code>GROUP BY</code> and <code>HAVING</code> to Django's <code>QuerySet.annotate</code> and <code>QuerySet.aggregate</code>. I'm trying to translate this SQL query into ORM speak</p>
<pre><code>SELECT EXTRACT(year FROM pub_date) as year, EXTRACT(month from pub_date) as m... | 5 | 2009-12-15T16:43:37Z | 1,910,930 | <p>You can make an extract with dates:
<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#dates-field-kind-order-asc" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/models/querysets/#dates-field-kind-order-asc</a></p>
| 2 | 2009-12-15T22:35:14Z | [
"python",
"django",
"orm",
"group-by"
] |
buildbot: run svn with --trust-server-cert | 1,908,856 | <p>I am trying to install buildbot for my project.</p>
<p>I always run my svn commands with trust-server-cert option. How can I pass that to SVN thru buildbot?</p>
<p>I don't see there is a way for doing that. What is the shortest workaround?</p>
| 1 | 2009-12-15T16:58:54Z | 1,909,091 | <p>Use the <code>extra_args</code> argument to the <code>buildbot.steps.source.SVN</code> <a href="http://djmitche.github.com/buildbot/docs/0.7.11/#SVN" rel="nofollow">constructor</a>.</p>
| 2 | 2009-12-15T17:36:17Z | [
"python",
"svn",
"project-management",
"build-process",
"buildbot"
] |
Netcat implementation in Python | 1,908,878 | <p>I found <a href="http://4thmouse.com/index.php/2008/02/22/netcat-clone-in-three-languages-part-ii-python/">this</a> and am using it as my base, but it wasn't working right out of the box. My goal is also to treat it as a package instead of a command line utility, so my code changes will reflect that.</p>
<pre><code... | 21 | 2009-12-15T17:01:41Z | 1,909,208 | <p>if you don't mind scrapping that code altogether, you might like to look at <a href="http://www.secdev.org/projects/scapy/" rel="nofollow">scapy</a> -- it's basically the swiss army knife of packet tools in python. take a look at the <a href="http://www.secdev.org/projects/scapy/doc/usage.html#interactive-tutorial"... | 2 | 2009-12-15T17:56:30Z | [
"python",
"netcat"
] |
Netcat implementation in Python | 1,908,878 | <p>I found <a href="http://4thmouse.com/index.php/2008/02/22/netcat-clone-in-three-languages-part-ii-python/">this</a> and am using it as my base, but it wasn't working right out of the box. My goal is also to treat it as a package instead of a command line utility, so my code changes will reflect that.</p>
<pre><code... | 21 | 2009-12-15T17:01:41Z | 1,909,355 | <p>Does it work if you just use <a href="http://www.openbsd.org/cgi-bin/man.cgi?query=nc&sektion=1"><code>nc</code></a>?</p>
<p>I think you should try something a little simpler:</p>
<pre><code>import socket
def netcat(hostname, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.conn... | 34 | 2009-12-15T18:18:02Z | [
"python",
"netcat"
] |
Netcat implementation in Python | 1,908,878 | <p>I found <a href="http://4thmouse.com/index.php/2008/02/22/netcat-clone-in-three-languages-part-ii-python/">this</a> and am using it as my base, but it wasn't working right out of the box. My goal is also to treat it as a package instead of a command line utility, so my code changes will reflect that.</p>
<pre><code... | 21 | 2009-12-15T17:01:41Z | 27,767,560 | <p>The following is a working implementation on python3:</p>
<pre><code>import socket
def netcat(host, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, int(port)))
s.sendall(content.encode())
s.shutdown(socket.SHUT_WR)
while True:
data = s.recv(4096)
... | 4 | 2015-01-04T16:17:49Z | [
"python",
"netcat"
] |
Python: list problems | 1,908,961 | <p>I've read in a text file and converted each line into a list.</p>
<p>using this script:</p>
<pre><code>l = [s.strip().split() for s in open("cluster2.wcnf").readlines()]
</code></pre>
<p>How would i go about :</p>
<ol>
<li>the file it opens is dynamic rather than static? i.e. the user
chooses the file to open.</... | 0 | 2009-12-15T17:12:41Z | 1,908,977 | <p>First of all, you must drop <code>.readlines()</code> from your list comprehension.<br>
Second, <code>l</code> is a list of lists, to access first line just do: <code>l[0]</code>. First element of the first line would then be <code>l[0][0]</code>.</p>
<p>The problem with the growing file I believe cannot be solved ... | 1 | 2009-12-15T17:15:33Z | [
"python",
"list",
"select",
"line"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.