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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
How to define a class in Python | 1,495,666 | <p>Quite simple, I'm learning python and I can't find a reference that tells me how to write the following:</p>
<pre><code>public class Team {
private String name;
private String logo;
private int members;
public Team(){}
// getters/setters
}
</code></pre>
<p>Later:</p>
<pre><code>Team t... | 40 | 2009-09-30T01:02:16Z | 1,495,740 | <p>Here is what I would recommend:</p>
<pre class="lang-py prettyprint-override"><code>class Team(object):
def __init__(self, name=None, logo=None, members=0):
self.name = name
self.logo = logo
self.members = members
team = Team("Oscar", "http://...", 10)
team2 = Team()
team2.name = "Fred... | 87 | 2009-09-30T01:35:29Z | [
"python"
] |
How close is Python to being able to wrap it in a workbook type skin? | 1,496,039 | <p>With my luck this question will be closed too quickly. I see a tremendous possibility for a python application that basically is like a workbook. Imagine if you will that instead of writing code you select from a menu of choices. For example, the File menu would have an open command that lets the user navigate to... | 1 | 2009-09-30T03:51:01Z | 1,496,055 | <p>There are Python application that are based on generating code -- the most amazing one probably <a href="http://www.resolversystems.com/products/" rel="nofollow">Resolver One</a>, which focuses on spreadsheets (and hinges on IronPython). With that exception, however, interacting based on the UI paradigm you have in ... | 3 | 2009-09-30T03:58:23Z | [
"python",
"wrapper",
"openaccess"
] |
How close is Python to being able to wrap it in a workbook type skin? | 1,496,039 | <p>With my luck this question will be closed too quickly. I see a tremendous possibility for a python application that basically is like a workbook. Imagine if you will that instead of writing code you select from a menu of choices. For example, the File menu would have an open command that lets the user navigate to... | 1 | 2009-09-30T03:51:01Z | 1,496,078 | <p>Your idea kinda reminded me of something I stumbled across months ago: <a href="http://www.ailab.si/orange/" rel="nofollow">http://www.ailab.si/orange/</a></p>
| 1 | 2009-09-30T04:10:42Z | [
"python",
"wrapper",
"openaccess"
] |
How close is Python to being able to wrap it in a workbook type skin? | 1,496,039 | <p>With my luck this question will be closed too quickly. I see a tremendous possibility for a python application that basically is like a workbook. Imagine if you will that instead of writing code you select from a menu of choices. For example, the File menu would have an open command that lets the user navigate to... | 1 | 2009-09-30T03:51:01Z | 1,496,242 | <p>Is your concept very similar to Microsoft Access? Generally programmers tend not to write such programs because they produce such horrible code that the authors themselves would never want to use their program.</p>
| 0 | 2009-09-30T05:22:43Z | [
"python",
"wrapper",
"openaccess"
] |
Aggregating multiple feeds with Universal Feed Parser | 1,496,067 | <p>Having great luck working with single-source feed parsing in Universal Feed Parser, but now I need to run multiple feeds through it and generate chronologically interleaved output (not RSS). Seems like I'll need to iterate through URLs and stuff every entry into a list of dictionaries, then sort that by the entry ti... | 0 | 2009-09-30T04:04:18Z | 1,496,285 | <p>You could throw the feeds into a database and then generate a new feed from this database.</p>
<p>Consider looking into two feedparser-based RSS aggregators: <a href="http://www.planetplanet.org/" rel="nofollow">Planet Feed Aggregator</a> and <a href="http://www.feedjack.org/" rel="nofollow">FeedJack</a> (Django ba... | 2 | 2009-09-30T05:48:24Z | [
"python",
"django"
] |
Aggregating multiple feeds with Universal Feed Parser | 1,496,067 | <p>Having great luck working with single-source feed parsing in Universal Feed Parser, but now I need to run multiple feeds through it and generate chronologically interleaved output (not RSS). Seems like I'll need to iterate through URLs and stuff every entry into a list of dictionaries, then sort that by the entry ti... | 0 | 2009-09-30T04:04:18Z | 1,496,616 | <p>Here is already suggestion to store data in the database, e.g. <code>bsddb.btopen()</code> or any RDBMS.</p>
<p>Take a look at <code>heapq.merge()</code> and <code>bisect.insort()</code> or use one of B-tree implementations if you'd like to merge data in memory.</p>
| 1 | 2009-09-30T07:40:27Z | [
"python",
"django"
] |
wxpython -- threads and window events | 1,496,092 | <p>I have a wxPython application (<a href="http://www.OpenSTV.org" rel="nofollow">http://www.OpenSTV.org</a>) that counts ballots using methods that have multiple rounds. I'd like to do two things:</p>
<p>(1) For a large number of ballots, this can be a bit slow, so I'd like to show the user a progress dialog so he d... | 4 | 2009-09-30T04:16:26Z | 1,496,118 | <p>There are several ways to call the main thread wxPython thread from a process thread. The simplest is <strong>wx.CallAfter()</strong> which will always execute the functional passed to it in the main thread. You can also use <strong>wx.PostEvent()</strong> and there's an example of this in the demo (labeled: Threa... | 3 | 2009-09-30T04:32:09Z | [
"python",
"events",
"multithreading",
"wxpython",
"window"
] |
wxpython -- threads and window events | 1,496,092 | <p>I have a wxPython application (<a href="http://www.OpenSTV.org" rel="nofollow">http://www.OpenSTV.org</a>) that counts ballots using methods that have multiple rounds. I'd like to do two things:</p>
<p>(1) For a large number of ballots, this can be a bit slow, so I'd like to show the user a progress dialog so he d... | 4 | 2009-09-30T04:16:26Z | 1,496,127 | <p>Use <a href="http://docs.python.org/library/queue.html">Queue</a> to communicate and synchronize among threads, with each thread "owning" and exclusively interacting with a resource that's not handy to share.</p>
<p>In GUI toolkits where only the main thread can really handle the GUI, the main thread should play al... | 5 | 2009-09-30T04:38:29Z | [
"python",
"events",
"multithreading",
"wxpython",
"window"
] |
Problem loading transparent background sprites in pygame | 1,496,106 | <p>I'm trying to load a transparent image into pygame using the following code:</p>
<pre><code>def load_image(name, colorkey=None):
fullname = os.path.join('data', name)
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image:', fullname
raise... | 1 | 2009-09-30T04:25:56Z | 1,497,001 | <p>You call image.convert(). From the <a href="http://www.pygame.org/docs/ref/surface.html#Surface.convert" rel="nofollow">docs for Surface.convert</a>:</p>
<blockquote>
<p>"The converted Surface will have no
pixel alphas. They will be stripped if
the original had them. See
*Surface.convert_alpha* - change the... | 3 | 2009-09-30T09:22:54Z | [
"python",
"pygame"
] |
In Python in GAE, what is the best way to limit the risk of executing untrusted code? | 1,496,115 | <p>I would like to enable students to submit python code solutions to a few simple python problems. My applicatoin will be running in GAE. How can I limit the risk from malicios code that is sumitted? I realize that this is a hard problem and I have read related Stackoverflow and other posts on the subject. I am curiou... | 3 | 2009-09-30T04:30:46Z | 1,496,145 | <p>@mjv's smiley comment is actually spot-on: make sure the submitter IS identified and associated with the code in question (which presumably is going to be sent to a task queue), and log any diagnostics caused by an individual's submissions.</p>
<p>Beyond that, you can indeed prepare a test-space that's more restric... | 5 | 2009-09-30T04:47:15Z | [
"python",
"google-app-engine"
] |
In Python in GAE, what is the best way to limit the risk of executing untrusted code? | 1,496,115 | <p>I would like to enable students to submit python code solutions to a few simple python problems. My applicatoin will be running in GAE. How can I limit the risk from malicios code that is sumitted? I realize that this is a hard problem and I have read related Stackoverflow and other posts on the subject. I am curiou... | 3 | 2009-09-30T04:30:46Z | 1,496,953 | <p>You really can't sandbox Python code inside App Engine with any degree of certainty. Alex's idea of logging who's running what is a good one, but if the user manages to break out of the sandbox, they can erase the event logs. The only place this information would be safe is in the per-request logging, since users ca... | 2 | 2009-09-30T09:12:03Z | [
"python",
"google-app-engine"
] |
In Python in GAE, what is the best way to limit the risk of executing untrusted code? | 1,496,115 | <p>I would like to enable students to submit python code solutions to a few simple python problems. My applicatoin will be running in GAE. How can I limit the risk from malicios code that is sumitted? I realize that this is a hard problem and I have read related Stackoverflow and other posts on the subject. I am curiou... | 3 | 2009-09-30T04:30:46Z | 5,614,660 | <p>Here's an idea. Instead of running the code server-side, run it client-side with Skuplt:</p>
<p><a href="http://www.skulpt.org/" rel="nofollow">http://www.skulpt.org/</a></p>
<p>This is both safer, and easier to implement.</p>
| 0 | 2011-04-10T20:53:40Z | [
"python",
"google-app-engine"
] |
Passing a list of kwargs? | 1,496,346 | <p>Can I pass a list of kwargs to a method for brevity? This is what i'm attempting to do:</p>
<pre><code>def method(**kwargs):
#do something
keywords = (keyword1 = 'foo', keyword2 = 'bar')
method(keywords)
</code></pre>
| 43 | 2009-09-30T06:08:33Z | 1,496,355 | <p>Yes. You do it like this:</p>
<pre><code>def method(**kwargs):
print kwargs
keywords = {'keyword1': 'foo', 'keyword2': 'bar'}
method(keyword1='foo', keyword2='bar')
method(**keywords)
</code></pre>
<p>Running this in Python confirms these produce identical results:</p>
<pre><code>{'keyword2': 'bar', 'keyword1'... | 75 | 2009-09-30T06:11:41Z | [
"python",
"kwargs"
] |
Passing a list of kwargs? | 1,496,346 | <p>Can I pass a list of kwargs to a method for brevity? This is what i'm attempting to do:</p>
<pre><code>def method(**kwargs):
#do something
keywords = (keyword1 = 'foo', keyword2 = 'bar')
method(keywords)
</code></pre>
| 43 | 2009-09-30T06:08:33Z | 1,496,356 | <p>Do you mean a dict? Sure you can:</p>
<pre><code>def method(**kwargs):
#do something
keywords = {keyword1: 'foo', keyword2: 'bar'}
method(**keywords)
</code></pre>
| 1 | 2009-09-30T06:12:09Z | [
"python",
"kwargs"
] |
Passing a list of kwargs? | 1,496,346 | <p>Can I pass a list of kwargs to a method for brevity? This is what i'm attempting to do:</p>
<pre><code>def method(**kwargs):
#do something
keywords = (keyword1 = 'foo', keyword2 = 'bar')
method(keywords)
</code></pre>
| 43 | 2009-09-30T06:08:33Z | 1,496,424 | <p>As others have pointed out, you can do what you want by passing a dict. There are various ways to construct a dict. One that preserves the <code>keyword=value</code> style you attempted is to use the <a href="http://docs.python.org/library/stdtypes.html#mapping-types-dict">dict</a> built-in:</p>
<pre><code>keywords... | 6 | 2009-09-30T06:35:18Z | [
"python",
"kwargs"
] |
Passing a list of kwargs? | 1,496,346 | <p>Can I pass a list of kwargs to a method for brevity? This is what i'm attempting to do:</p>
<pre><code>def method(**kwargs):
#do something
keywords = (keyword1 = 'foo', keyword2 = 'bar')
method(keywords)
</code></pre>
| 43 | 2009-09-30T06:08:33Z | 29,567,960 | <p>So when I've come here I was looking for a way to pass several **kwargs in one function - for later use in further functions. Because this, not that surprisingly, doesn't work:</p>
<pre><code>def func1(**f2_x, **f3_x):
...
</code></pre>
<p>With some own 'experimental' coding I came to the obviously way how to... | 3 | 2015-04-10T18:03:07Z | [
"python",
"kwargs"
] |
SQLAlchemy - MapperExtension.before_delete not called | 1,496,429 | <p>I have question regarding the SQLAlchemy. I have database which contains Items, every Item has assigned more Records (1:n). And the Record is partially stored in the database, but it also has an assigned file (1:1) on the filesystem.</p>
<p>What I want to do is to delete the assigned file when the Record is removed... | 0 | 2009-09-30T06:38:34Z | 1,506,587 | <p>A delete + insert of two records that ultimately have the same primary key within a single flush are converted into a single update right now. this is not the best behavior - it really should delete then insert, so that the various events assigned to those activities are triggered as expected (not just mapper exte... | 3 | 2009-10-01T21:22:54Z | [
"python",
"sqlalchemy"
] |
How to treat the first line of a file differently in Python? | 1,496,456 | <p>I often need to process large text files containing headers in the first line. The headers are often treated differently to the body of the file, or my processing of the body is dependent on the headers. Either way I need to treat the first line as a special case.
I could use simple line iteration and set a flag:</p... | 7 | 2009-09-30T06:46:59Z | 1,496,477 | <p>You could:</p>
<pre><code>processHeader(f.readline())
for line in f:
processBody(line)
</code></pre>
| 12 | 2009-09-30T06:52:33Z | [
"python",
"file",
"iteration"
] |
How to treat the first line of a file differently in Python? | 1,496,456 | <p>I often need to process large text files containing headers in the first line. The headers are often treated differently to the body of the file, or my processing of the body is dependent on the headers. Either way I need to treat the first line as a special case.
I could use simple line iteration and set a flag:</p... | 7 | 2009-09-30T06:46:59Z | 1,496,489 | <p>Use iter()</p>
<pre><code>it_f = iter(f)
header = it_f.next()
processHeader(header)
for line in it_f:
processBody(line)
</code></pre>
<p>It works with any iterable object.</p>
| 3 | 2009-09-30T06:56:22Z | [
"python",
"file",
"iteration"
] |
How to treat the first line of a file differently in Python? | 1,496,456 | <p>I often need to process large text files containing headers in the first line. The headers are often treated differently to the body of the file, or my processing of the body is dependent on the headers. Either way I need to treat the first line as a special case.
I could use simple line iteration and set a flag:</p... | 7 | 2009-09-30T06:46:59Z | 1,496,491 | <pre><code>f = file("test")
processHeader(f.next()) #or next(f) for py3
for line in f:
processBody(line)
</code></pre>
<p>This works.</p>
<p>Edit:</p>
<p>Changed <code>.__next__</code> to <code>next</code> (they <em>are</em> equivalent, but I suppose next is more concise).</p>
<p>Regaring <code>file</code> vs <... | 8 | 2009-09-30T06:56:41Z | [
"python",
"file",
"iteration"
] |
How to treat the first line of a file differently in Python? | 1,496,456 | <p>I often need to process large text files containing headers in the first line. The headers are often treated differently to the body of the file, or my processing of the body is dependent on the headers. Either way I need to treat the first line as a special case.
I could use simple line iteration and set a flag:</p... | 7 | 2009-09-30T06:46:59Z | 1,496,514 | <p>Large text files with headers in the first line? So it's tabular data. </p>
<p>Just to make sure: Have you looked at the <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv</a> module? It should handle all tabular data except such where the fields are not delimited but defined by position. And it d... | 2 | 2009-09-30T07:05:58Z | [
"python",
"file",
"iteration"
] |
Guidance on optimising Python runtime for embedded systems with low system resources | 1,496,761 | <p>My team is incorporating the Python 2.4.4 runtime into our project in order to leverage some externally developed functionality. </p>
<p>Our platform has a 450Mhz SH4 application core and limited memory for use by the Python runtime and application. </p>
<p>We have ported Python, but initial testing has highlighte... | 9 | 2009-09-30T08:25:53Z | 1,497,008 | <p>Perhaps it is hard to believe, but CPython version 2.4 <a href="http://evanjones.ca/python-memory.html" rel="nofollow">never releases memory to the OS</a>. This is allegedly fixed in verion Python 2.5.</p>
<p>In addition, performance (processor-wise) was improved in Python 2.5 and Python 2.6 on top of that.</p>
<p... | 5 | 2009-09-30T09:25:39Z | [
"python",
"performance",
"memory",
"embedded",
"garbage-collection"
] |
how to obtain physical drives in Windows | 1,496,842 | <p>I'm programming in Python with a wrapper of the kernel32 dll, so I can use any functions of this dll, like GetLogicalDrives(), for instance. I'm trying to obtain the information of the physical drives, <strong>even if they are not mounted</strong>. I've seen a question similar to this, but I need the information of ... | 1 | 2009-09-30T08:47:55Z | 1,497,004 | <p>FindFirstVolume and FindNextVolume <em>may</em> be what you need.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa364425%28VS.85%29.aspx" rel="nofollow">MSDN FindFirstVolume page</a></p>
<p>There's an example that searches for volumes and list all paths for each volume, and at first sight, it seems to al... | 1 | 2009-09-30T09:23:46Z | [
"python",
"windows"
] |
how to obtain physical drives in Windows | 1,496,842 | <p>I'm programming in Python with a wrapper of the kernel32 dll, so I can use any functions of this dll, like GetLogicalDrives(), for instance. I'm trying to obtain the information of the physical drives, <strong>even if they are not mounted</strong>. I've seen a question similar to this, but I need the information of ... | 1 | 2009-09-30T08:47:55Z | 1,497,529 | <p>Use Tim Golden's wmi module. Here's the <a href="http://timgolden.me.uk/python/wmi%5Fcookbook.html#find-drive-types" rel="nofollow">cookbook</a> entry:</p>
<pre><code>import wmi
w = wmi.WMI()
for drive in w.Win32_LogicalDisk():
print drive.Caption, drive.Size, drive.FreeSpace
</code></pre>
<p>prints</p>
<pre... | 3 | 2009-09-30T11:21:11Z | [
"python",
"windows"
] |
how to obtain physical drives in Windows | 1,496,842 | <p>I'm programming in Python with a wrapper of the kernel32 dll, so I can use any functions of this dll, like GetLogicalDrives(), for instance. I'm trying to obtain the information of the physical drives, <strong>even if they are not mounted</strong>. I've seen a question similar to this, but I need the information of ... | 1 | 2009-09-30T08:47:55Z | 1,497,789 | <p>Also you can try win32 module for Python.</p>
| 1 | 2009-09-30T12:24:08Z | [
"python",
"windows"
] |
how to obtain physical drives in Windows | 1,496,842 | <p>I'm programming in Python with a wrapper of the kernel32 dll, so I can use any functions of this dll, like GetLogicalDrives(), for instance. I'm trying to obtain the information of the physical drives, <strong>even if they are not mounted</strong>. I've seen a question similar to this, but I need the information of ... | 1 | 2009-09-30T08:47:55Z | 1,497,814 | <p><a href="http://msdn.microsoft.com/en-us/library/aa365730%28VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa365730%28VS.85%29.aspx</a></p>
<p>GetLogicalDrives()
GetLogicalDriveStrings()</p>
<p>Look like what you want. But they work off A:, B: C: etc, rather than \?\HardDisk or whatever</p>
| -2 | 2009-09-30T12:31:15Z | [
"python",
"windows"
] |
how to obtain physical drives in Windows | 1,496,842 | <p>I'm programming in Python with a wrapper of the kernel32 dll, so I can use any functions of this dll, like GetLogicalDrives(), for instance. I'm trying to obtain the information of the physical drives, <strong>even if they are not mounted</strong>. I've seen a question similar to this, but I need the information of ... | 1 | 2009-09-30T08:47:55Z | 11,803,238 | <p>How about <code>Win32_DiskDrive</code> wmi class?</p>
<pre><code>c = wmi.WMI()
dd = c.Win32_DiskDrive()[0]
print.dd
</code></pre>
<p>More about Win32_DiskDrive <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394132%28v=vs.85%29.aspx" rel="nofollow">on the msdn</a></p>
| 0 | 2012-08-03T21:00:28Z | [
"python",
"windows"
] |
Web Service client in Python using ZSI - "Classless struct didn't get dictionary" | 1,496,910 | <p>I am trying to write a sample client in Python using ZSI for a simple Web Service. The Web Service WSDL is following:</p>
<pre><code><?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/test/" xmlns:wsd... | 1 | 2009-09-30T09:00:31Z | 1,553,177 | <p>Finally, I have found the solution. </p>
<p>I should run like this:</p>
<pre><code>from ZSI.ServiceProxy import ServiceProxy
service = ServiceProxy('test.wsdl')
service.NewOperation(NewOperationRequest='test')
</code></pre>
<p>The reason of the problem was that the name of the parameter was missing (sic!) - silly... | 3 | 2009-10-12T07:27:15Z | [
"python",
"wsdl",
"zsi"
] |
Python 2.5 and 2.6 and Numpy compatibility problem | 1,496,942 | <p>In the computers of our laboratory, which have Python 2.6.2 installed in them, my program, which is an animation of the 2D random walk and diffusion, works perfectly. </p>
<p>However, I can't get the exact same program to work on my laptop, which has Python 2.5. By that not working, I mean the animation is screwed;... | 1 | 2009-09-30T09:09:19Z | 1,497,061 | <p>Numpy for python 2.6 appears to be downloadable from <a href="http://sourceforge.net/projects/numpy/files/" rel="nofollow">numpy sourceforge</a> or can be compiled from source</p>
| 1 | 2009-09-30T09:38:26Z | [
"python",
"numpy",
"compatibility"
] |
Python 2.5 and 2.6 and Numpy compatibility problem | 1,496,942 | <p>In the computers of our laboratory, which have Python 2.6.2 installed in them, my program, which is an animation of the 2D random walk and diffusion, works perfectly. </p>
<p>However, I can't get the exact same program to work on my laptop, which has Python 2.5. By that not working, I mean the animation is screwed;... | 1 | 2009-09-30T09:09:19Z | 1,497,175 | <p>The various (<code>matplotlib.pyplot</code>) graphical backends do not behave in exactly the same way.</p>
<p>You could try setting the backend so that it is the same on both machines:</p>
<pre><code>matplotlib.use('GTKagg') # Right after importing matplotlib
</code></pre>
<p>For a list of possible backends, you... | 2 | 2009-09-30T10:03:38Z | [
"python",
"numpy",
"compatibility"
] |
How to display outcoming and incoming SOAP message for ZSI.ServiceProxy in Python? | 1,497,038 | <p>How to display a SOAP message generated by ZSI.ServiceProxy and a respond from a Web Service when a Web Service method is invoked?</p>
| 1 | 2009-09-30T09:33:13Z | 1,501,943 | <p>Here is some <a href="http://pywebsvcs.sourceforge.net/zsi.html#SECTION0012200000000000000000" rel="nofollow">documentation</a> on the ServiceProxy class. The constructor accepts a <code>tracefile</code> argument which can be any object with a <code>write</code> method, so this looks like what you are after. Modifyi... | 2 | 2009-10-01T04:50:22Z | [
"python",
"web-services",
"zsi"
] |
question related to reverse function and kwargs | 1,497,258 | <p>To reverse lookup an url by means of name or View_name we will use reverse function in the views like below</p>
<pre><code>reverse("calendarviewurl2", kwargs={"year":theyear,"month":themonth})
</code></pre>
<p>and reverse function signature is as follows </p>
<p><a href="http://code.djangoproject.com/browser/djan... | 4 | 2009-09-30T10:27:07Z | 1,497,331 | <p>Didn't you look at the <a href="http://code.djangoproject.com/browser/django/trunk/django/core/urlresolvers.py#L305">signature</a>,</p>
<pre><code>def reverse(viewname, urlconf=None, args=None, kwargs=None,
prefix=None, current_app=None):
</code></pre>
<p>takes no <code>**kwargs</code> at al... | 9 | 2009-09-30T10:41:25Z | [
"python",
"django"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 1,497,517 | <p>The reason UUIDs are long is because they contain lots of information so that they can be guaranteed to be globally unique.</p>
<p>If you want something shorter, then you'll need to do something like generate a random string, checking whether it is in the universe of already generated strings, and repeating until y... | 2 | 2009-09-30T11:18:33Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 1,497,533 | <p>It doesn't really matter that this is Python, but you just need a hash function that maps to the length you want. For example, maybe use MD5 and then take just the first <code>n</code> characters. You'll have to watch out for collisions in that case, though, so you might want to pick something a little more robust... | 1 | 2009-09-30T11:21:54Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 1,497,541 | <p>I'm not sure most URL shorteners use a random string. My impression is they write the URL to a database, then use the integer ID of the new record as the short URL, encoded base 36 or 62 (letters+digits).</p>
<p>Python code to convert an int to a string in arbitrary bases is <a href="http://code.activestate.com/re... | 14 | 2009-09-30T11:24:40Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 1,497,573 | <p><strong>Edit</strong>: Here, I wrote a module for you. Use it. <a href="http://code.activestate.com/recipes/576918/">http://code.activestate.com/recipes/576918/</a></p>
<p><hr /></p>
<p>Counting up from 1 will guarantee short, unique URLS. /1, /2, /3 ... etc.</p>
<p>Adding uppercase and lowercase letters to your... | 22 | 2009-09-30T11:32:51Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 1,497,728 | <p>I don't know if you can use this, but we generate content objects in Zope that get unique numeric ids based on current time strings, in millis (eg, 1254298969501)</p>
<p>Maybe you can guess the rest. Using the recipe described here:
<a href="http://stackoverflow.com/questions/561486/how-to-convert-an-integer-to-the... | 1 | 2009-09-30T12:09:42Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 4,640,654 | <p>This module will do what you want, guaranteeing that the string is globally unique (it is a UUID):</p>
<p><a href="http://pypi.python.org/pypi/shortuuid/0.1" rel="nofollow">http://pypi.python.org/pypi/shortuuid/0.1</a></p>
<p>If you need something shorter, you should be able to truncate it to the desired length an... | 3 | 2011-01-09T17:41:46Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 5,494,143 | <p>Try this <a href="http://code.google.com/p/tiny4py/" rel="nofollow">http://code.google.com/p/tiny4py/</a> ... It's still under development, but very useful!!</p>
| 0 | 2011-03-31T00:43:03Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 28,075,828 | <p><strong>My Goal:</strong> Generate a unique identifier of a specified fixed length consisting of the characters <code>0-9</code> and <code>a-z</code>. For example:</p>
<pre class="lang-none prettyprint-override"><code>zcgst5od
9x2zgn0l
qa44sp0z
61vv1nl5
umpprkbt
ylg4lmcy
dec0lu1t
38mhd8i5
rx00yf0e
kc2qdc07
</code><... | 0 | 2015-01-21T20:00:54Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
How to make unique short URL with Python? | 1,497,504 | <p>How can I make unique URL in Python a la <a href="http://imgur.com/gM19g">http://imgur.com/gM19g</a> or <a href="http://tumblr.com/xzh3bi25y">http://tumblr.com/xzh3bi25y</a>
When using uuid from python I get a very large one. I want something shorter for URLs.</p>
| 26 | 2009-09-30T11:16:10Z | 31,250,977 | <p><a href="http://hashids.org/python/" rel="nofollow">Hashids</a> is an awesome tool for this.</p>
<p>Edit:</p>
<p>Here's how to use Hashids to generate a unique short URL with Python:</p>
<pre><code>from hashids import Hashids
pk = 123 # Your object's id
domain = 'imgur.com' # Your domain
hashids = Hashids(salt=... | 0 | 2015-07-06T16:27:40Z | [
"python",
"url",
"uuid",
"tinyurl",
"short-url"
] |
Can Python determine the class of a object accessing a method | 1,497,683 | <p>Is there anyway to do something like this:</p>
<pre><code>class A:
def foo(self):
if isinstance(caller, B):
print "B can't call methods in A"
else:
print "Foobar"
class B:
def foo(self, ref): ref.foo()
class C:
def foo(self, ref): ref.foo()
a = A();
B().foo(a) ... | 1 | 2009-09-30T11:58:36Z | 1,497,696 | <p>The caller is always an instance of A. The fact that you're calling it inside a B method doesn't change that. In other words: Insiode <code>B.foo</code>, <code>ref</code> is an instance of <code>A</code>, so calling <code>ref.foo()</code> is a call on <code>A</code>, <code>B</code> is not involved on that call (it c... | 4 | 2009-09-30T12:02:03Z | [
"python",
"introspection"
] |
Can Python determine the class of a object accessing a method | 1,497,683 | <p>Is there anyway to do something like this:</p>
<pre><code>class A:
def foo(self):
if isinstance(caller, B):
print "B can't call methods in A"
else:
print "Foobar"
class B:
def foo(self, ref): ref.foo()
class C:
def foo(self, ref): ref.foo()
a = A();
B().foo(a) ... | 1 | 2009-09-30T11:58:36Z | 1,497,768 | <p>Assuming the caller is a method, then yes you can, by looking in the previous frame, and picking out <code>self</code> from the locals.</p>
<pre><code>class Reciever:
def themethod(self):
frame = sys._getframe(1)
arguments = frame.f_code.co_argcount
if arguments == 0:
print "... | 5 | 2009-09-30T12:20:31Z | [
"python",
"introspection"
] |
Can Python determine the class of a object accessing a method | 1,497,683 | <p>Is there anyway to do something like this:</p>
<pre><code>class A:
def foo(self):
if isinstance(caller, B):
print "B can't call methods in A"
else:
print "Foobar"
class B:
def foo(self, ref): ref.foo()
class C:
def foo(self, ref): ref.foo()
a = A();
B().foo(a) ... | 1 | 2009-09-30T11:58:36Z | 1,498,298 | <p>Something like this may meet your needs better:</p>
<pre><code>class A(object):
def foo(self):
# do stuff
class B(A):
def foo(self):
raise NotImplementedError
class C(A):
pass
</code></pre>
<p>...but it's difficult to say without knowing exactly what you're trying to do.</p>
| 0 | 2009-09-30T13:58:58Z | [
"python",
"introspection"
] |
Is it OK if objects from different classes interact with each other? | 1,498,009 | <p>I just started to use the object oriented programming in Python. I wander if it is OK if I create a method of a class which use objects from another class. In other words, when I call a method of the first class I give an object from the second class as one of the arguments. And then, the considered methods (of the ... | 4 | 2009-09-30T13:11:04Z | 1,498,030 | <p>If you're talking about passing an instance of one object to the method of a another one, then yes of course it's allowed! And it's considered fine practice.</p>
<p>If you want to know more about good object oriented coding, may I offer some suggested readings:</p>
<p><em>Design Patterns: Elements of Reusable Obj... | 7 | 2009-09-30T13:13:29Z | [
"python",
"oop"
] |
Is it OK if objects from different classes interact with each other? | 1,498,009 | <p>I just started to use the object oriented programming in Python. I wander if it is OK if I create a method of a class which use objects from another class. In other words, when I call a method of the first class I give an object from the second class as one of the arguments. And then, the considered methods (of the ... | 4 | 2009-09-30T13:11:04Z | 1,498,033 | <p>I see no problem with that, it happens all the time. Do you have a specific problem you're trying to solve or just asking a general question without a context?</p>
| 0 | 2009-09-30T13:13:35Z | [
"python",
"oop"
] |
Is it OK if objects from different classes interact with each other? | 1,498,009 | <p>I just started to use the object oriented programming in Python. I wander if it is OK if I create a method of a class which use objects from another class. In other words, when I call a method of the first class I give an object from the second class as one of the arguments. And then, the considered methods (of the ... | 4 | 2009-09-30T13:11:04Z | 1,498,085 | <p>What you're talking about is fine. In fact most data types (string, int, boolean, etc.) in Python are objects, so pretty much every method works in the way you described.</p>
| 1 | 2009-09-30T13:22:11Z | [
"python",
"oop"
] |
Is it OK if objects from different classes interact with each other? | 1,498,009 | <p>I just started to use the object oriented programming in Python. I wander if it is OK if I create a method of a class which use objects from another class. In other words, when I call a method of the first class I give an object from the second class as one of the arguments. And then, the considered methods (of the ... | 4 | 2009-09-30T13:11:04Z | 1,498,152 | <p>The answer is that it os MORE than OK, it's in fact the whole point.</p>
<p>What is not "OK" is when objects start fiddling with the internals of each other. You can prevent this from happening accidentally, by calling things that are meant to be internal with a leading underscore (or two, which makes it internal a... | 1 | 2009-09-30T13:32:39Z | [
"python",
"oop"
] |
Is it OK if objects from different classes interact with each other? | 1,498,009 | <p>I just started to use the object oriented programming in Python. I wander if it is OK if I create a method of a class which use objects from another class. In other words, when I call a method of the first class I give an object from the second class as one of the arguments. And then, the considered methods (of the ... | 4 | 2009-09-30T13:11:04Z | 1,498,499 | <p>The Law of Demeter is general guidance on which methods and objects you can interact with in good faith. </p>
<p>It is guidance. You <em>can</em> make code that works that doesn't follow the LoD, but it is a good guide and helps you build "structure shy systems" -- something you will appreciate later when you try... | 0 | 2009-09-30T14:32:13Z | [
"python",
"oop"
] |
Performance of Python worth the cost? | 1,498,155 | <p>I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.</p>
<p>I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM). </p>
<p>The main... | 5 | 2009-09-30T13:32:45Z | 1,498,176 | <p>Python is very slow at handling large amounts of non-string data. For some operations, you may see that it is 1000 times slower than C/C++, so yes, you should investigate into this and do necessary benchmarks before you make time-critical algorithms in Python.</p>
<p>However, you can extend python with modules in C... | 11 | 2009-09-30T13:36:28Z | [
"python",
"c",
"embedded",
"fuzzy-logic"
] |
Performance of Python worth the cost? | 1,498,155 | <p>I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.</p>
<p>I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM). </p>
<p>The main... | 5 | 2009-09-30T13:32:45Z | 1,498,214 | <p>In general, you shouldn't obsess over performance until you've actually seen it become a problem. Since we don't know the details of your app, we can't say how it'd perform if implemented in Python. And since you haven't implemented it yet, neither can you.</p>
<p>Implement the version you're most comfortable with,... | 35 | 2009-09-30T13:44:01Z | [
"python",
"c",
"embedded",
"fuzzy-logic"
] |
Performance of Python worth the cost? | 1,498,155 | <p>I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.</p>
<p>I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM). </p>
<p>The main... | 5 | 2009-09-30T13:32:45Z | 1,498,739 | <p>Make it work, then make it work fast.</p>
| 5 | 2009-09-30T15:09:50Z | [
"python",
"c",
"embedded",
"fuzzy-logic"
] |
Performance of Python worth the cost? | 1,498,155 | <p>I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.</p>
<p>I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM). </p>
<p>The main... | 5 | 2009-09-30T13:32:45Z | 1,499,253 | <p>If most of your runtime is spent in C libraries, the language you use to call these libraries isn't important. What language are your time-eating libraries written in ?</p>
| 1 | 2009-09-30T16:28:37Z | [
"python",
"c",
"embedded",
"fuzzy-logic"
] |
Performance of Python worth the cost? | 1,498,155 | <p>I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.</p>
<p>I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM). </p>
<p>The main... | 5 | 2009-09-30T13:32:45Z | 1,502,231 | <p>From your description, speed should not be much of a concern (and you can use C, cython, whatever you want to make it faster), but memory would be. For environments with 64 Mb max (where the OS and all should fit as well, right ?), I think there is a good chance that python may not be the right tool for target depl... | 0 | 2009-10-01T06:33:58Z | [
"python",
"c",
"embedded",
"fuzzy-logic"
] |
Performance of Python worth the cost? | 1,498,155 | <p>I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.</p>
<p>I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM). </p>
<p>The main... | 5 | 2009-09-30T13:32:45Z | 1,612,690 | <p>I never really measured the performance of pyfuzzy's examples, but as the new version 0.1.0 can read FCL files as FFLL does. Just describe your fuzzy system in this format, write some wrappers, and check the performance of both variants.</p>
<p>For reading FCL with pyfuzzy you need the antlr python runtime, but aft... | 0 | 2009-10-23T10:55:21Z | [
"python",
"c",
"embedded",
"fuzzy-logic"
] |
Pymsn/Papyon contact memberships | 1,498,634 | <p>Dear Stackoverflow, I'm having the following problem:</p>
<p>I'm programming a bot for MSN Messenger in python with the pymsn/papyon library. I have everything running, except that I don't know how to accept new contacts already pending or new requests. Sadly the documentation of the library is very bad. I've achie... | 0 | 2009-09-30T14:55:13Z | 1,872,443 | <p>if you want check there is any contact, just list all you contact and check if the contact status is pending. Short code like:</p>
<pre><code>for contact in self.client._address_book.contacts:
if contact.is_pending:
self.client._address_book.accept_contact_invitation(contact)
</code></pre>
<p>is_pendin... | 0 | 2009-12-09T08:37:57Z | [
"python",
"bots",
"msn-messenger"
] |
Django: form values not updating when model updates | 1,498,763 | <p>I am creating a form that uses MultipleChoiceField. The values for this field are derived from another model. This method works fine, however, I am noticing (on the production server) that when I add a new item to the model in question (NoticeType), the form does not dynamically update. I have to restart the serv... | 4 | 2009-09-30T15:14:17Z | 1,498,918 | <p>My hunch is that the class definition is only being processed once on load rather than for each instantiation. Try adding the CHOICES computation to the <strong>init</strong> method like so:</p>
<pre><code>def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
CHOICES = ... | 6 | 2009-09-30T15:32:57Z | [
"python",
"django",
"django-forms"
] |
Django: form values not updating when model updates | 1,498,763 | <p>I am creating a form that uses MultipleChoiceField. The values for this field are derived from another model. This method works fine, however, I am noticing (on the production server) that when I add a new item to the model in question (NoticeType), the form does not dynamically update. I have to restart the serv... | 4 | 2009-09-30T15:14:17Z | 1,499,297 | <p>Although mherren is right that you can fix this problem by defining your choices in the <code>__init__</code> method, there is an easier way: use the <code>ModelMultipleChoiceField</code> which is specifically designed to take a queryset, and updates dynamically.</p>
<pre><code>class EditUserProfileForm(forms.Form)... | 8 | 2009-09-30T16:37:14Z | [
"python",
"django",
"django-forms"
] |
How to get the PATH separator in Python? | 1,499,019 | <p>When multiple directories need to be concatenated, as in an executable search path, there is an os-dependent separator character. For Windows it's <code>';'</code>, for Linux it's <code>':'</code>. Is there a way in Python to get which character to split on?</p>
<p>In the discussions to this question <a href="htt... | 106 | 2009-09-30T15:51:47Z | 1,499,033 | <p><a href="http://docs.python.org/library/os.html#os.pathsep"><code>os.pathsep</code></a></p>
| 163 | 2009-09-30T15:53:44Z | [
"python",
"operating-system"
] |
How to get the PATH separator in Python? | 1,499,019 | <p>When multiple directories need to be concatenated, as in an executable search path, there is an os-dependent separator character. For Windows it's <code>';'</code>, for Linux it's <code>':'</code>. Is there a way in Python to get which character to split on?</p>
<p>In the discussions to this question <a href="htt... | 106 | 2009-09-30T15:51:47Z | 1,499,034 | <p>It is os.pathsep</p>
| 25 | 2009-09-30T15:53:53Z | [
"python",
"operating-system"
] |
How to get the PATH separator in Python? | 1,499,019 | <p>When multiple directories need to be concatenated, as in an executable search path, there is an os-dependent separator character. For Windows it's <code>';'</code>, for Linux it's <code>':'</code>. Is there a way in Python to get which character to split on?</p>
<p>In the discussions to this question <a href="htt... | 106 | 2009-09-30T15:51:47Z | 35,413,644 | <p>Making it a little more explicit (For python newbies like me)</p>
<pre><code>import os
print(os.pathsep)
</code></pre>
| 6 | 2016-02-15T15:53:55Z | [
"python",
"operating-system"
] |
Python - importing package classes into console global namespace | 1,499,119 | <p>I'm having a spot of trouble getting my python classes to work within the python console. I want to automatically import all of my classes into the global namespace so I can use them without any prefix.module.names.</p>
<p>Here's what I've got so far...</p>
<pre><code>projectname/
|-__init__.py
|
|-main_stuff/
|... | 8 | 2009-09-30T16:04:52Z | 1,499,164 | <p>You want to use a different form of import.</p>
<p>In <code>projectname/main_stuff/__init__.py</code>:</p>
<pre><code>from other_stuff import *
__all__ = ["main1", "main2", "main3"]
</code></pre>
<p>When you use a statement like this:</p>
<pre><code>import foo
</code></pre>
<p>You are defining the name foo in t... | 14 | 2009-09-30T16:13:14Z | [
"python",
"import",
"console",
"namespaces",
"global"
] |
Running python script as another user | 1,499,268 | <p>On a Linux box I want to run a Python script as another user.</p>
<p>I've already made a wrapper program in C++ that calls the script, since I've realized that the ownership of running the script is decided by the ownership of the python interpreter. After that I change the C++ program to a different user and run t... | 8 | 2009-09-30T16:31:05Z | 1,499,282 | <p>Use the command <code>sudo</code>.</p>
<p>In order to run a program as a user, the system must "authenticate" that user.</p>
<p>Obviously, <code>root</code> can run any program as any user, and any user can <code>su</code> to another user with a password.</p>
<p>The program <code>sudo</code> can be configured to ... | 0 | 2009-09-30T16:33:49Z | [
"python",
"linux"
] |
Running python script as another user | 1,499,268 | <p>On a Linux box I want to run a Python script as another user.</p>
<p>I've already made a wrapper program in C++ that calls the script, since I've realized that the ownership of running the script is decided by the ownership of the python interpreter. After that I change the C++ program to a different user and run t... | 8 | 2009-09-30T16:31:05Z | 1,499,313 | <p>Give those users the ability to <code>sudo su $dedicated_username</code> and tailor the permissions on your system so that <code>$dedicated_user</code> has sufficient, but not excessive, access.</p>
| 1 | 2009-09-30T16:39:46Z | [
"python",
"linux"
] |
Running python script as another user | 1,499,268 | <p>On a Linux box I want to run a Python script as another user.</p>
<p>I've already made a wrapper program in C++ that calls the script, since I've realized that the ownership of running the script is decided by the ownership of the python interpreter. After that I change the C++ program to a different user and run t... | 8 | 2009-09-30T16:31:05Z | 1,499,317 | <p>It sounds like you want to use the <a href="http://en.wikipedia.org/wiki/Setuid" rel="nofollow">setuid</a> bit</p>
| 4 | 2009-09-30T16:40:19Z | [
"python",
"linux"
] |
Running python script as another user | 1,499,268 | <p>On a Linux box I want to run a Python script as another user.</p>
<p>I've already made a wrapper program in C++ that calls the script, since I've realized that the ownership of running the script is decided by the ownership of the python interpreter. After that I change the C++ program to a different user and run t... | 8 | 2009-09-30T16:31:05Z | 1,499,386 | <p>You can set the user with os.setuid(), and you can get the uid with pwd.
Like so:</p>
<pre><code>>>> import pwd, os
>>> uid = pwd.getpwnam('root')[2]
>>> os.setuid(uid)
</code></pre>
<p>Obviously this only works if the user or executable has the permission to do so. Exactly how to set th... | 11 | 2009-09-30T16:53:11Z | [
"python",
"linux"
] |
App Engine Python how to handle urls? | 1,499,485 | <p>I just want to ask a simple question, as I don't imagine how to do it.</p>
<p>In the app.yaml, when I want to declare query string parameter, how do I do it?</p>
<p>For example, to make a multi language site, I create the url in this format:</p>
<pre><code>mysite.com/english/aboutus
mysite.com/italiano/aboutus
<... | 0 | 2009-09-30T17:11:41Z | 1,499,554 | <p>Instead you could use the webapp framework to handle the URL's.</p>
<p>For example, in index.py</p>
<pre><code>application = webapp.WSGIApplication(
[('/english', EnglishHandler)],
[('/italiano', ItalianHandler)],
de... | 2 | 2009-09-30T17:28:09Z | [
"python",
"google-app-engine"
] |
App Engine Python how to handle urls? | 1,499,485 | <p>I just want to ask a simple question, as I don't imagine how to do it.</p>
<p>In the app.yaml, when I want to declare query string parameter, how do I do it?</p>
<p>For example, to make a multi language site, I create the url in this format:</p>
<pre><code>mysite.com/english/aboutus
mysite.com/italiano/aboutus
<... | 0 | 2009-09-30T17:11:41Z | 1,499,770 | <p>The <code>SCRIPT_NAME</code> environ entry contains the path under which your script was invoked. Haven't tested this in GAE specifically, but it's something WSGI inherited from <a href="http://hoohoo.ncsa.illinois.edu/cgi/env.html#protocol" rel="nofollow">CGI</a>.</p>
<pre><code>language= environ['SCRIPT_NAME'][1:... | 1 | 2009-09-30T18:10:34Z | [
"python",
"google-app-engine"
] |
App Engine Python how to handle urls? | 1,499,485 | <p>I just want to ask a simple question, as I don't imagine how to do it.</p>
<p>In the app.yaml, when I want to declare query string parameter, how do I do it?</p>
<p>For example, to make a multi language site, I create the url in this format:</p>
<pre><code>mysite.com/english/aboutus
mysite.com/italiano/aboutus
<... | 0 | 2009-09-30T17:11:41Z | 1,503,689 | <p>I remember doing something like this:</p>
<p>in app.yaml put</p>
<pre><code>- url: /(.*)/(.*)/?
script: main.py
</code></pre>
<p>and in main.py</p>
<pre><code>class MainHandler(webapp.RequestHandler):
def get(self, Urlpart1, Urlpart2):
def main():
application = webapp.WSGIApplication([('/(.*)/(.*)/'... | 4 | 2009-10-01T12:33:20Z | [
"python",
"google-app-engine"
] |
App Engine Python how to handle urls? | 1,499,485 | <p>I just want to ask a simple question, as I don't imagine how to do it.</p>
<p>In the app.yaml, when I want to declare query string parameter, how do I do it?</p>
<p>For example, to make a multi language site, I create the url in this format:</p>
<pre><code>mysite.com/english/aboutus
mysite.com/italiano/aboutus
<... | 0 | 2009-09-30T17:11:41Z | 1,569,489 | <p>There're 39 human languages supported. Best way seems comply via lib/django/django/conf/locale/
<a href="http://classifiedsmarket.appspot.com?hl=kn" rel="nofollow">Here's</a> an app that translates all engines messages via parameter hl=[languageCode]
[code disposable][2]</p>
| 0 | 2009-10-14T23:05:12Z | [
"python",
"google-app-engine"
] |
How do I define a SWIG typemap for a reference to pointer? | 1,499,569 | <p>I have a Publisher class written in C++ with the following two methods:</p>
<pre><code>PublishField(char* name, double* address);
GetFieldReference(char* name, double*& address);
</code></pre>
<p>Python bindings for this class are being generated using SWIG. In my swig .i file I have the following:</p>
<pre>... | 1 | 2009-09-30T17:31:01Z | 1,510,406 | <p>Here is a working solution that I came up with.</p>
<p>Add a wrapper function to the swig.i file:</p>
<pre><code>%inline %{
double * GetReference(char* name, Publisher* publisher)
{
double* ptr = new double;
publisher->GetFieldReference(name, ptr);
return ptr;
}
%}
</code>... | 1 | 2009-10-02T15:55:05Z | [
"c++",
"python",
"swig"
] |
How do I define a SWIG typemap for a reference to pointer? | 1,499,569 | <p>I have a Publisher class written in C++ with the following two methods:</p>
<pre><code>PublishField(char* name, double* address);
GetFieldReference(char* name, double*& address);
</code></pre>
<p>Python bindings for this class are being generated using SWIG. In my swig .i file I have the following:</p>
<pre>... | 1 | 2009-09-30T17:31:01Z | 2,561,620 | <p>This typemap should solve the problem - </p>
<pre><code>// Typemaps for double *&
%typemap(in) double *& (double *ppDouble = NULL) %{
$1 = &ppDouble ;
%}
%typemap(argout) double *& {
*(double **)&jarg2 = *$1;
}
%typemap(javain) double *& "$javainput"
</code></pre>
<p>You may need to che... | 0 | 2010-04-01T15:38:14Z | [
"c++",
"python",
"swig"
] |
With multiple Python installs, how does MacPorts know which one to install MySQLdb for? | 1,499,572 | <p>I just upgraded the default Python 2.5 on Leopard to 2.6 via the installer on www.python.org. Upon doing so, the MySQLdb I had installed was no longer found. So I tried reinstalling it via <code>port install py-mysql</code>, and it succeeded, but MySQLdb was still not <code>import</code>able. So then I tried to <cod... | 0 | 2009-09-30T17:32:09Z | 1,500,063 | <p>The <code>MacPorts</code> python ports generally follow a pattern: if the port name starts with just <code>py-</code>, it is configured to install into MacPorts python2.4. Likewise <code>py25-</code> requires python2.5. For the MacPorts python2.6, you want <a href="http://www.macports.org/ports.php?by=name&sub... | 2 | 2009-09-30T19:04:55Z | [
"python",
"mysql",
"osx"
] |
With multiple Python installs, how does MacPorts know which one to install MySQLdb for? | 1,499,572 | <p>I just upgraded the default Python 2.5 on Leopard to 2.6 via the installer on www.python.org. Upon doing so, the MySQLdb I had installed was no longer found. So I tried reinstalling it via <code>port install py-mysql</code>, and it succeeded, but MySQLdb was still not <code>import</code>able. So then I tried to <cod... | 0 | 2009-09-30T17:32:09Z | 2,302,542 | <p>You also need python_select (or is it select_python?) to change the default python used.</p>
| 1 | 2010-02-20T14:47:59Z | [
"python",
"mysql",
"osx"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 1,499,847 | <p>You can get the current revision number of a checkout using, on the command line, "<code>svn info</code>".</p>
<p>For instance :</p>
<pre><code>$ svn info
Chemin : .
URL : http://.../trunk
Racine du dépôt : http://...
UUID du dépôt : 128b9c1a-...-612a326c9977
Révision : 185
Type de nÅud : répertoire
Tâche ... | 3 | 2009-09-30T18:21:48Z | [
"php",
"python",
"svn"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 1,499,851 | <p>I would probably write out the version number to a text file somewhere within the website using the post-commit hook and then just read that file when loading your page.</p>
<p><a href="http://svnbook.red-bean.com/en/1.1/ch05s02.html" rel="nofollow">More on using hooks here</a></p>
| 4 | 2009-09-30T18:22:44Z | [
"php",
"python",
"svn"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 1,499,859 | <p>You could just shell out to the command line and run svn info. Just keep in mind this could be a mixed revision. You could also run an svn up and the last line of STDOUT will give you the revision number. </p>
<p>Or, are you wanting to use the svn API? You might also want to look at the TortoiseSVN code from SubWCR... | 0 | 2009-09-30T18:24:15Z | [
"php",
"python",
"svn"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 1,499,894 | <p>I like the solution used by MediaWiki, reading the contents of <code>.svn/entities</code>. Check the first answer on this question: <a href="http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code">http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-i... | 2 | 2009-09-30T18:32:05Z | [
"php",
"python",
"svn"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 1,499,895 | <p>If you're looking for a Python implementation, check out <a href="http://pysvn.tigris.org/" rel="nofollow">pysvn</a>, you can invoke the <a href="http://pysvn.tigris.org/docs/pysvn%5Fprog%5Fref.html#pysvn%5Fclient%5Finfo" rel="nofollow">info command</a> to get details including the current revision:</p>
<pre><code>... | 2 | 2009-09-30T18:32:05Z | [
"php",
"python",
"svn"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 1,499,911 | <p>This works for svn version 1.6.2. But be warned, different SVN versions use different formats of the .svn folder.</p>
<pre><code><?php
$contents = file_get_contents(dirname(__FILE__) . '/.svn/entries');
preg_match("/dir\n(.+)/", $contents, $matches);
$svnRevision = $matches[1];
print "This Directory's SVN Rev... | 3 | 2009-09-30T18:35:38Z | [
"php",
"python",
"svn"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 1,500,651 | <p>Following Lance, here's a command line one-liner.</p>
<pre><code>svn log -q --limit 1 http://svnbox/path/to/repo/trunk \
| php -r 'fgets(STDIN); preg_match("/(\d+)/", fgets(STDIN), $m); echo $m[0];'
</code></pre>
| 3 | 2009-09-30T21:02:36Z | [
"php",
"python",
"svn"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 1,501,219 | <p>Subversion includes the <a href="http://svnbook.red-bean.com/en/1.7/svn.ref.svnversion.re.html" rel="nofollow">svnversion</a> tool for exactly this purpose. A working copy may actually have local modifications, or may consist of a mix of revisions. <code>svnversion</code> knows how to handle that; see the examples i... | 13 | 2009-09-30T23:37:06Z | [
"php",
"python",
"svn"
] |
How to programmatically get SVN revision number? | 1,499,811 | <p><a href="http://stackoverflow.com/questions/681770/how-to-programmatically-get-svn-revision-description-and-author-in-c">Like this question</a>, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise m... | 7 | 2009-09-30T18:17:47Z | 4,346,943 | <p>I know this is pretty old, but I thought I'd offer up how I do this in PHP for my web apps:</p>
<p>Put this in a PHP file in your app, and set the SVN Keywords property for "Date Revision Author HeadURL Id" (keyword substitution in the file).</p>
<pre><code>$SVN_rev = "\$LastChangedRevision$";
$SVN_headURL = "\$He... | 1 | 2010-12-03T15:21:45Z | [
"php",
"python",
"svn"
] |
Python/WebApp Google App Engine - testing for user/pass in the headers | 1,499,832 | <p>When you call a web service like this:</p>
<pre><code> username = 'test12'
password = 'test34'
client = httplib2.Http(".cache")
client.add_credentials(username,password)
URL = "http://localhost:8080/wyWebServiceTest"
response, content = client.request(URL)
</code></pre>
<p>How do you get the use... | 4 | 2009-09-30T18:20:00Z | 1,500,047 | <p>httplib2 will only pass the credentials after a 401 response from the web server, after which the credentials should be sent in an Authorization: header.</p>
| 1 | 2009-09-30T19:01:08Z | [
"python",
"google-app-engine",
"web-applications"
] |
Python/WebApp Google App Engine - testing for user/pass in the headers | 1,499,832 | <p>When you call a web service like this:</p>
<pre><code> username = 'test12'
password = 'test34'
client = httplib2.Http(".cache")
client.add_credentials(username,password)
URL = "http://localhost:8080/wyWebServiceTest"
response, content = client.request(URL)
</code></pre>
<p>How do you get the use... | 4 | 2009-09-30T18:20:00Z | 1,500,356 | <p>The credentials will appear in the Authorization header. The steps work like this:</p>
<ol>
<li>Client makes a request to your app with no attempt at authorization</li>
<li>Server responds with a "401 Authorization Required" response, and the "WWW-Authenticate" header set to 'Basic realm="something"' (for basic aut... | 3 | 2009-09-30T20:04:28Z | [
"python",
"google-app-engine",
"web-applications"
] |
Python/WebApp Google App Engine - testing for user/pass in the headers | 1,499,832 | <p>When you call a web service like this:</p>
<pre><code> username = 'test12'
password = 'test34'
client = httplib2.Http(".cache")
client.add_credentials(username,password)
URL = "http://localhost:8080/wyWebServiceTest"
response, content = client.request(URL)
</code></pre>
<p>How do you get the use... | 4 | 2009-09-30T18:20:00Z | 1,500,515 | <p>I haven't tested this code (insert smiley) but I think this is the sort of thing you need. Basically your credentials won't be in the header if your server hasn't bounced a 401 back to your client (the client needs to know the realm to know what credentials to provide).</p>
<pre><code>class MYREALM_securepage(weba... | 7 | 2009-09-30T20:36:30Z | [
"python",
"google-app-engine",
"web-applications"
] |
Django: How to set initial values for a field in an inline model formset? | 1,500,121 | <p>I have what I think should be a simple problem. I have an inline model formset, and I'd like to make a select field have a default selected value of the currently logged in user. In the view, I'm using Django's Authentication middleware, so getting the user is a simple matter of accessing <code>request.user</code>... | 7 | 2009-09-30T19:15:53Z | 1,500,771 | <p>I'm not sure how to handle this in inline formsets, but the following approach will work for normal Forms and ModelForms:</p>
<p>You can't set this as part of the model definition, but you can set it during the form initialization:</p>
<pre><code>def __init__(self, logged_in_user, *args, **kwargs):
super(self.... | 4 | 2009-09-30T21:32:18Z | [
"python",
"django",
"default-value",
"django-forms"
] |
Django: How to set initial values for a field in an inline model formset? | 1,500,121 | <p>I have what I think should be a simple problem. I have an inline model formset, and I'd like to make a select field have a default selected value of the currently logged in user. In the view, I'm using Django's Authentication middleware, so getting the user is a simple matter of accessing <code>request.user</code>... | 7 | 2009-09-30T19:15:53Z | 8,223,856 | <p>This does the trick. It works by setting the initial values of all "extra" forms.</p>
<pre><code>formset = MyFormset(instance=myinstance)
user = request.user
for form in formset.forms:
if 'user' not in form.initial:
form.initial['user'] = user.pk
</code></pre>
| 3 | 2011-11-22T08:25:00Z | [
"python",
"django",
"default-value",
"django-forms"
] |
Django: How to set initial values for a field in an inline model formset? | 1,500,121 | <p>I have what I think should be a simple problem. I have an inline model formset, and I'd like to make a select field have a default selected value of the currently logged in user. In the view, I'm using Django's Authentication middleware, so getting the user is a simple matter of accessing <code>request.user</code>... | 7 | 2009-09-30T19:15:53Z | 31,100,197 | <p>I'm using Rune Kaagaard's idea above, except I noticed that formsets provide an extra_forms property: <a href="https://docs.djangoproject.com/en/1.8/_modules/django/forms/formsets/" rel="nofollow">django.forms.formsets code</a></p>
<pre><code>@property
def extra_forms(self):
"""Return a list of all the extra fo... | 0 | 2015-06-28T13:11:48Z | [
"python",
"django",
"default-value",
"django-forms"
] |
How to tell when nosetest is running programmatically | 1,500,214 | <p><strong>nosetest</strong> is the default test framework in Turbogeras 2.0. The application has a websetup.py module that initialise the database. I use mysql for my development and production environment and websetup works fine, but <strong>nosetest</strong> uses sqlite on memory and when it tries to initialise th... | 0 | 2009-09-30T19:34:50Z | 1,500,318 | <p>I don't use TurboGears, but is there not a setting or global somewhere that indicates that the tests are running? In large systems, there are often small changes that need to be made when running tests. Switching between SQLite and MySQL is just one example.</p>
| 0 | 2009-09-30T19:55:57Z | [
"python",
"sqlalchemy",
"nosetests"
] |
How to tell when nosetest is running programmatically | 1,500,214 | <p><strong>nosetest</strong> is the default test framework in Turbogeras 2.0. The application has a websetup.py module that initialise the database. I use mysql for my development and production environment and websetup works fine, but <strong>nosetest</strong> uses sqlite on memory and when it tries to initialise th... | 0 | 2009-09-30T19:34:50Z | 1,509,700 | <p>Presumably if nose is running, the 'nose' top-level module will have been imported. You should be able to test that with</p>
<pre><code>if 'nose' in sys.modules:
print "Nose is running, or at least has been imported!"
#or whatever you need to do if nose is running
</code></pre>
<p>Of course this is not a f... | 0 | 2009-10-02T14:01:57Z | [
"python",
"sqlalchemy",
"nosetests"
] |
Programmatically determine maximum command line length with Python | 1,500,542 | <p>Does anyone know a portable way for Python to determine a system's maximum command line length? The program I'm working on builds a command and feeds it to subprocess. For systems with smaller command line length maximums, it is possible that the command will be too long. If I can detect that, the command can be ... | 0 | 2009-09-30T20:41:50Z | 1,500,652 | <p>Just ask sysconf:</p>
<p><code></p>
<pre>
os.sysconf(os.sysconf_names['SC_ARG_MAX'])
</pre>
<p></code></p>
| 4 | 2009-09-30T21:02:42Z | [
"python",
"command-line",
"subprocess"
] |
cProfile and Python: Finding the specific line number that code spends most time on | 1,500,564 | <p>I'm using cProfile, pstats and Gprof2dot to profile a rather long python script.</p>
<p>The results tell me that the most time is spent calling a method in an object I've defined. However, what I would really like is to know exactly what line number within that function is eating up the time. </p>
<p>Any idea's ho... | 5 | 2009-09-30T20:46:34Z | 1,500,791 | <p>Suppose the amount of time being "eaten up" is some number, like 40%. Then if you just interrupt the program or pause it at a random time, the probability is 40% that you will see it, precisely exposed on the call stack. Do this 10 times, and on 4 samples, +/-, you will see it.</p>
<p><a href="http://stackoverflow.... | 0 | 2009-09-30T21:36:48Z | [
"python",
"scripting",
"numbers",
"profiler",
"line"
] |
cProfile and Python: Finding the specific line number that code spends most time on | 1,500,564 | <p>I'm using cProfile, pstats and Gprof2dot to profile a rather long python script.</p>
<p>The results tell me that the most time is spent calling a method in an object I've defined. However, what I would really like is to know exactly what line number within that function is eating up the time. </p>
<p>Any idea's ho... | 5 | 2009-09-30T20:46:34Z | 1,500,818 | <p><code>cProfile</code> does not track line numbers within a function; it only tracks the line number of where the function was defined. </p>
<p><code>cProfile</code> attempts to duplicate the behavior of <code>profile</code> (which is pure Python). <code>profile</code> uses <code>pstats</code> to store the data fr... | 2 | 2009-09-30T21:42:54Z | [
"python",
"scripting",
"numbers",
"profiler",
"line"
] |
cProfile and Python: Finding the specific line number that code spends most time on | 1,500,564 | <p>I'm using cProfile, pstats and Gprof2dot to profile a rather long python script.</p>
<p>The results tell me that the most time is spent calling a method in an object I've defined. However, what I would really like is to know exactly what line number within that function is eating up the time. </p>
<p>Any idea's ho... | 5 | 2009-09-30T20:46:34Z | 1,502,200 | <p>There is a <a href="http://pypi.python.org/pypi/line%5Fprofiler/1.0b2" rel="nofollow">line profiler</a> in python written by Robert Kern.</p>
| 3 | 2009-10-01T06:25:22Z | [
"python",
"scripting",
"numbers",
"profiler",
"line"
] |
Python XML Serializers | 1,500,575 | <p>Can some recommend an XML serializer that is element or attribute centric, and that doesn't use key-value pairs. </p>
<p>For example, GAE db.model has a to_xml() function but it writes out like this: </p>
<pre><code> <property name="firstname" type="string">John</property>
<property name="lastnam... | 0 | 2009-09-30T20:47:56Z | 1,501,536 | <p><a href="http://www.strangegizmo.com/products/pyxslt/doc/pyxslt.serialize-module.html" rel="nofollow">pyxslt.serialize</a> looks closest to your specs but not a 100% map (for example, it doesn't record the type -- just turns everything into strings). Could still be a good basis from where to customize (maybe by copy... | 2 | 2009-10-01T01:56:24Z | [
"python",
"xml-serialization"
] |
What is the right way to override the copy/deepcopy operations on an object in Python? | 1,500,718 | <p>So just to establish, I feel like I understand the difference between copy vs. deepcopy in the copy module and I've used copy.copy and copy.deepcopy before successfully, but this is the first time I've actually gone about overloading the __copy__ and __deepcopy__ methods. I've already Googled around and looked thro... | 32 | 2009-09-30T21:18:45Z | 1,500,788 | <p>I might be a bit off on the specifics, but here goes;</p>
<p>From the <a href="http://docs.python.org/library/copy.html" rel="nofollow"><code>copy</code> docs</a>;</p>
<blockquote>
<ul>
<li>A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objec... | 2 | 2009-09-30T21:35:54Z | [
"python"
] |
What is the right way to override the copy/deepcopy operations on an object in Python? | 1,500,718 | <p>So just to establish, I feel like I understand the difference between copy vs. deepcopy in the copy module and I've used copy.copy and copy.deepcopy before successfully, but this is the first time I've actually gone about overloading the __copy__ and __deepcopy__ methods. I've already Googled around and looked thro... | 32 | 2009-09-30T21:18:45Z | 1,500,887 | <p>The recommendations for customizing are at the very end of the <a href="http://docs.python.org/library/copy.html">docs page</a>:</p>
<blockquote>
<p>Classes can use the same interfaces to
control copying that they use to
control pickling. See the description
of module pickle for information on
these metho... | 26 | 2009-09-30T21:58:58Z | [
"python"
] |
What is the right way to override the copy/deepcopy operations on an object in Python? | 1,500,718 | <p>So just to establish, I feel like I understand the difference between copy vs. deepcopy in the copy module and I've used copy.copy and copy.deepcopy before successfully, but this is the first time I've actually gone about overloading the __copy__ and __deepcopy__ methods. I've already Googled around and looked thro... | 32 | 2009-09-30T21:18:45Z | 15,774,013 | <p>Putting together Alex Martelli's answer and Rob Young's comment you get the following code:</p>
<pre><code>from copy import copy, deepcopy
class A(object):
def __init__(self):
print 'init'
self.v = 10
self.z = [2,3,4]
def __copy__(self):
cls = self.__class__
result ... | 24 | 2013-04-02T20:46:44Z | [
"python"
] |
What is the right way to override the copy/deepcopy operations on an object in Python? | 1,500,718 | <p>So just to establish, I feel like I understand the difference between copy vs. deepcopy in the copy module and I've used copy.copy and copy.deepcopy before successfully, but this is the first time I've actually gone about overloading the __copy__ and __deepcopy__ methods. I've already Googled around and looked thro... | 32 | 2009-09-30T21:18:45Z | 24,621,200 | <p>Its not clear from your problem why you need to override these methods, since you don't want to do any customization to the copying methods.</p>
<p>Anyhow, if you do want to customize the deep copy (e.g. by sharing some attributes and copying others), here is a solution:</p>
<pre><code>from copy import deepcopy
... | 1 | 2014-07-07T22:53:32Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.