prefix
stringclasses
1 value
input_text
stringlengths
19
27.3k
target_text
stringlengths
2
24.8k
QA
splitting tuples in python best practice have method in my python code that returns tuple row from sql query let us say it has three fields jobid label username for ease of passing it around between functions have been passing the entire tuple as variable called job eventually however want to get at the bits so have be...
perhaps this is overkill for your case but would be tempted to create job class that takes the tuple as its constructor argument and has respective properties on it would then pass instances of this class around instead
QA
splitting tuples in python best practice have method in my python code that returns tuple row from sql query let us say it has three fields jobid label username for ease of passing it around between functions have been passing the entire tuple as variable called job eventually however want to get at the bits so have be...
would use dictionary you can convert the tuple to dictionary this way values querycode keys jobid label username job dict keys values for in xrange len values this will first create an array jobid val label val username val and then convert that to dictionary if the result order or count changes you just need to change...
QA
is there python module for regex matching in zip files have over million text files compressed into zip files also have list of about model names of phones want to find out the number of times particular model was mentioned in the text files is there any python module which can do regex match on the files without unzip...
is not it at least theoretically possible to read in the zip huffman coding and then translate the regexp into the huffman code might this be more efficient than first de compressing the data then running the regexp note know it would not be quite that simple you would also have to deal with other aspects of the zip co...
QA
splitting tuples in python best practice have method in my python code that returns tuple row from sql query let us say it has three fields jobid label username for ease of passing it around between functions have been passing the entire tuple as variable called job eventually however want to get at the bits so have be...
staale there is better way job dict zip keys values
QA
how do do monkeypatching in python have had to do some introspection in python and it was not pretty name sys getframe code name os path split name co filename name co firstlineno name co name to get something like foo py bar blah blah in our debugging output would ideally like to prepend anything to stderr with this s...
the python inspect module makes this lot easier and cleaner
QA
standard way to open folder window in linux want to open folder window in the appropriate file manager from within cross platform windows mac linux python application on osx can open window in the finder with os system open foldername and on windows with os startfile foldername what about unix linux is there standard w...
this would probably have to be done manually or have as config item since there are many file managers that users may want to use providing way for command options as well there might be an function that launches the defaults for kde or gnome in their respective toolkits but have not had reason to look for them
QA
standard way to open folder window in linux want to open folder window in the appropriate file manager from within cross platform windows mac linux python application on osx can open window in the finder with os system open foldername and on windows with os startfile foldername what about unix linux is there standard w...
you are going to have to do this based on the running window manager osx and windows have defacto standard way because there is only one choice you should not need to specify the exact filemanager application though this should be possible to do through the wm know gnome does and it is important to do this in kde since...
QA
standard way to open folder window in linux want to open folder window in the appropriate file manager from within cross platform windows mac linux python application on osx can open window in the finder with os system open foldername and on windows with os startfile foldername what about unix linux is there standard w...
os system xdg open foldername xdg open can be used for files urls also
QA
what is tuple useful for am learning python for class now and we just covered tuples as one of the data types read the wikipedia page on it but could not figure out where such data type would be useful in practice can have some examples perhaps in python where an immutable set of numbers would be needed how is this dif...
tuples are used whenever you want to return multiple results from function since they are immutable they can be used as keys for dictionary lists cannot
QA
what is tuple useful for am learning python for class now and we just covered tuples as one of the data types read the wikipedia page on it but could not figure out where such data type would be useful in practice can have some examples perhaps in python where an immutable set of numbers would be needed how is this dif...
find them useful when you always deal with two or more objects as set
QA
what is tuple useful for am learning python for class now and we just covered tuples as one of the data types read the wikipedia page on it but could not figure out where such data type would be useful in practice can have some examples perhaps in python where an immutable set of numbers would be needed how is this dif...
list can always replace tuple with respect to functionality except apparently as keys in dict however tuple can make things go faster the same is true for for example immutable strings in java when will you ever need to be unable to alter your strings never just read decent discussion on limiting what you can do in ord...
QA
what is tuple useful for am learning python for class now and we just covered tuples as one of the data types read the wikipedia page on it but could not figure out where such data type would be useful in practice can have some examples perhaps in python where an immutable set of numbers would be needed how is this dif...
tuples make good dictionary keys when you need to combine more than one piece of data into your key and do not feel like making class for it bob hello hello en us hi there have used this feature primarily to create dictionary with keys that are coordinates of the vertices of mesh however in my particular case the exact...
QA
what is tuple useful for am learning python for class now and we just covered tuples as one of the data types read the wikipedia page on it but could not figure out where such data type would be useful in practice can have some examples perhaps in python where an immutable set of numbers would be needed how is this dif...
tuple is useful for storing multiple values as you note tuple is just like list that is immutable once created you cannot add remove swap elements one benefit of being immutable is that because the tuple is fixed size it allows the run time to perform certain optimizations this is particularly beneficial when tupple is...
QA
what is tuple useful for am learning python for class now and we just covered tuples as one of the data types read the wikipedia page on it but could not figure out where such data type would be useful in practice can have some examples perhaps in python where an immutable set of numbers would be needed how is this dif...
tuples and lists have the same uses in general immutable data types in general have many benefits mostly about concurrency issues so when you have lists that are not volatile in nature and you need to guarantee that no consumer is altering it you may use tuple typical examples are fixed data in an application like comp...
QA
best way to extract text from word doc without using com automation is there reasonable way to extract plain text from word file that does not depend on com automation this is feature for web app deployed on non windows platform that is non negotiable in this case antiword seems like it might be reasonable option but i...
open office has an api
QA
best way to extract text from word doc without using com automation is there reasonable way to extract plain text from word file that does not depend on com automation this is feature for web app deployed on non windows platform that is non negotiable in this case antiword seems like it might be reasonable option but i...
if it is word docx you could unzip it and parse the xml files that are contained inside
QA
python deployment and usr bin env portability at the beginning of all my executable python scripts put the shebang line usr bin env python am running these scripts on system where env python yields python environment my scripts quickly fail because have manual check for compatible python version if sys version info rai...
pretty hackish solution if your check fails use this function which probably could be significantly improved to determine the best interpreter available determine if it is acceptable and if so relaunch your script with os system or something similar and your sys argv using the new interpreter import os import glob def ...
QA
python re sub multiline caret match the python docs say re multiline when specified the pattern character matches at the beginning of the string and at the beginning of each line immediately following each newline by default matches only at the beginning of the string so what is going on when get the following unexpect...
look at the definition of re sub sub pattern repl string count the th argument is the count you are using re multiline which is as the count not as flag you have to compile your regex if you wish to use flags re sub re compile re multiline flags argument was added in python so the full definition is now re sub pattern ...
QA
where can learn more about pypy translation function have been having hard time trying to understand pypy translation it looks like something absolutely revolutionary from simply reading the description however am hard pressed to find good documentation on actually translating real world piece of code to something such...
this document seems to go into quite bit of detail and think complete description is out of scope for stackoverflow answer http codespeak net pypy dist pypy doc translation html the general idea of translating from one language to another is not particularly revolutionary but it has only recently been gaining popularit...
QA
python deployment and usr bin env portability at the beginning of all my executable python scripts put the shebang line usr bin env python am running these scripts on system where env python yields python environment my scripts quickly fail because have manual check for compatible python version if sys version info rai...
morais that is an interesting idea but think maybe we can take it one step farther maybe there is way to use ian bicking virtualenv to see if we are running in an acceptable environment to begin with and if so do nothing check if there exists version specific executable on the path check if python exists for in reverse...
QA
get last day of the month in python is there way using python standard library to easily determine one function call the last day of given month if the standard library does not support that does the dateutil package support this
edit see blair conrad answer for cleaner solution import datetime datetime date datetime timedelta days datetime date
QA
get last day of the month in python is there way using python standard library to easily determine one function call the last day of given month if the standard library does not support that does the dateutil package support this
edit see my other answer it has better implementation than this one which leave here just in case someone is interested in seeing how one might roll your own calculator john millikin gives good answer with the added complication of calculating the first day of the next month the following is not particularly elegant bu...
QA
how can get commit message from bzr post commit hook am trying to write bzr post commit hook for my private bugtracker but am stuck at the function signature of post commit local master old revno old revid new revno mew revid how can extract the commit message for the branch from this with bzrlib in python
and the answer is like so def check commit msg local master old revno old revid new revno new revid branch local or master revision branch repository get revision new revid print revision message local and master are branch objects so once you have revision it is easy to extract the message
QA
best way to extract text from word doc without using com automation is there reasonable way to extract plain text from word file that does not depend on com automation this is feature for web app deployed on non windows platform that is non negotiable in this case antiword seems like it might be reasonable option but i...
using the openoffice api and python and andrew pitonyak excellent online macro book managed to do this section is the place to start one other tip to make it work without needing the screen at all is to use the hidden property ro propertyvalue readonly true hidden propertyvalue hidden true xdoc desktop loadcomponentfro...
QA
how to generate urls in django in django template language you can use url viewname args to generate url to specific view with parameters how can you programatically do the same in python code what need is to create list of menu items where each item has name url and an active flag whether it is the current page or not...
if you need to use something similar to the url template tag in your code django provides the django core urlresolvers reverse the reverse function has the following signature reverse viewname urlconf none args none kwargs none https docs djangoproject com en dev ref urlresolvers
QA
can write native iphone apps using python using pyobjc you can use python to write cocoa applications for os can write native iphone apps using python and if so how
not currently currently the only languages available to access the iphone sdk are objective and swift there is no technical reason why this could not change in the future but would not hold your breath for this happening in the short term that said objective and swift really are not too scary edit javascript with nativ...
QA
can write native iphone apps using python using pyobjc you can use python to write cocoa applications for os can write native iphone apps using python and if so how
you can use pyobjc on the iphone as well due to the excellent work by jay freeman saurik see iphone applications in python note that this requires jailbroken iphone at the moment
QA
best way to extract text from word doc without using com automation is there reasonable way to extract plain text from word file that does not depend on com automation this is feature for web app deployed on non windows platform that is non negotiable in this case antiword seems like it might be reasonable option but i...
use catdoc or antiword for this whatever gives the result that is the easiest to parse have embedded this in python functions so it is easy to use from the parsing system which is written in python import os def doc to text catdoc filename fi fo fe os popen catdoc filename fi close retval fo read erroroutput fe read fo...
QA
python web application framework for tight db gui coupling am firm believer of the heretic thought of tight coupling between the backend and frontend want existing implied knowledge about backend to be automatically made use of when generating user interfaces if varchar column has maximum with of characters there guis ...
you should have look at django and especially its newforms and admin modules the newforms module provides nice possibility to do server side validation with automated generation of error messages pages for the user adding ajax validation is also possible
QA
python web application framework for tight db gui coupling am firm believer of the heretic thought of tight coupling between the backend and frontend want existing implied knowledge about backend to be automatically made use of when generating user interfaces if varchar column has maximum with of characters there guis ...
believe that django models does not support composite primary keys see documentation but perhaps you can use sqlalchemy in django google search indicates that you can have not used django so do not know suggest you take look at toscawidgets dbsprockets including dbmechanic catwalk catwalk is an application for turbogea...
QA
how to find the mime type of file in python let us say you want to save bunch of files somewhere for instance in blobs let us say you want to dish these files out via web page and have the client automatically open the correct application viewer assumption the browser figures out which application viewer to use by the ...
the mimetypes module in the standard library will determine guess the mime type from file extension if users are uploading files the http post will contain the mime type of the file alongside the data for example django makes this data available as an attribute of the uploadedfile object
QA
how to find the mime type of file in python let us say you want to save bunch of files somewhere for instance in blobs let us say you want to dish these files out via web page and have the client automatically open the correct application viewer assumption the browser figures out which application viewer to use by the ...
you did not state what web server you were using but apache has nice little module called mime magic which it uses to determine the type of file when told to do so it reads some of the file content and tries to figure out what type it is based on the characters found and as dave webb mentioned the mimetypes module unde...
QA
get last day of the month in python is there way using python standard library to easily determine one function call the last day of given month if the standard library does not support that does the dateutil package support this
did not notice this earlier when was looking at the documentation for the calendar module but method called monthrange provides this information monthrange year month returns weekday of first day of the month and number of days in month for the specified year and month import calendar calendar monthrange calendar month...
QA
pros and cons of different approaches to web programming in python would like to do some server side scripting using python but am kind of lost with the number of ways to do that it starts with the do it yourself cgi approach and it seems to end with some pretty robust frameworks that would basically do all the job the...
if you have never done any cgi programming before think it would be worth doing one project perhaps just sample play site just for yourself using the diy approach you will learn lot more about how all the various parts work than you would by using framework this will help in you design and debug and so on all your futu...
QA
pros and cons of different approaches to web programming in python would like to do some server side scripting using python but am kind of lost with the number of ways to do that it starts with the do it yourself cgi approach and it seems to end with some pretty robust frameworks that would basically do all the job the...
if you decide to go with framework that is wsgi based for instance turbogears would recommend you go through the excellent article another do it yourself framework by ian bicking in the article he builds simple web application framework from scratch also check out the video creating web framework with wsgi by kevin dan...
QA
pros and cons of different approaches to web programming in python would like to do some server side scripting using python but am kind of lost with the number of ways to do that it starts with the do it yourself cgi approach and it seems to end with some pretty robust frameworks that would basically do all the job the...
cgi is great for low traffic websites but it has some performance problems for anything else this is because every time request comes in the server starts the cgi application in its own process this is bad for two reasons starting and stopping process can take time and you cannot cache anything in memory you can go wit...
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
your python interpreter is correct one stupid way of calculating modulus is to subtract or add the modulus until the resulting value is between and modulus mod mod mod or in your case mod mod
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
well divided by would be with remainder of do not believe that should be very platform dependent but have seen stranger things
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
it is indeed in modular arithmetic modulus is simply the remainder of division and the remainder of divided by is
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
the result of the modulus operation on negatives seems to be programming language dependent and here is listing http en wikipedia org wiki modulo operation
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
well should be right should be because that is the next allowed digit going in the reverse direction it cannot be since that is out of range and following along by that logic must be the easiest way to think of how it will work is that you keep adding or subtracting until the number falls between inclusive and exclusiv...
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
by the way most programming languages would disagree with python and give the result depending on the interpretation of modulus this is correct however the most agreed upon mathematical definition states that the modulus of and is the strictly positive rest of the division of more precisely are by definition
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
the result depends on the language python returns the sign of the divisor where for example returns the sign of the dividend ie returns in
QA
pros and cons of different approaches to web programming in python would like to do some server side scripting using python but am kind of lost with the number of ways to do that it starts with the do it yourself cgi approach and it seems to end with some pretty robust frameworks that would basically do all the job the...
the simplest web program is cgi script which is basically just program whose standard output is redirected to the web browser making the request in this approach every page has its own executable file which must be loaded and parsed on every request this makes it really simple to get something up and running but scales...
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
one explanation might be that negative numbers are stored using complement when the python interpreter tries to do the modulo operation it converts to unsigned value as such instead of doing it actually computes xffff ffff ffff fffd which is
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
as explained in other answers there are many choices for modulo operation with negative values in general different languages and different machine architectures will give different result according to the python reference manual the modulo operator always yields result with the same sign as its second operand or zero ...
QA
modulus operation with negatives values weird thing can you please tell me how much is according to my python interpreter is but do you have wise explanation for this have read that in some languages the result can be machine dependent but am not sure though
be careful not to rely on this mod behavior in on all oses and architectures if recall correctly tried to rely on code like float to keep in the range from to but negative numbers crept in when would compile on one os but things would work fine on another os this made for an evil time debugging since it only happened h...
QA
how do document module in python that is it if you want to document function or class you put string just after the definition for instance def foo this function does nothing pass but what about module how can document what file py does
it is easy you just add docstring at the top of the module
QA
how do document module in python that is it if you want to document function or class you put string just after the definition for instance def foo this function does nothing pass but what about module how can document what file py does
for the packages you can document it in init py for the modules you can add docstring simply in the module file all the information is here http www python org dev peps pep
QA
how do document module in python that is it if you want to document function or class you put string just after the definition for instance def foo this function does nothing pass but what about module how can document what file py does
you do it the exact same way put string in as the first statement in the module
QA
iterate over subclasses of given class in given module in python given module and class how can iterate or generate list of all subclasses of that exist in module
here is one way to do it import inspect def get subclasses mod cls yield the classes in module mod that inherit from cls for name obj in inspect getmembers mod if hasattr obj bases and cls in obj bases yield obj
QA
iterate over subclasses of given class in given module in python given module and class how can iterate or generate list of all subclasses of that exist in module
given the module foo py class foo object pass class bar foo pass class baz foo pass class grar exception pass def find subclasses module clazz for name in dir module getattr module name try if issubclass clazz yield name except typeerror pass import foo list foo find subclasses foo foo foo bar class foo bar baz class f...
QA
how to merge two python dictionaries in single expression have two python dictionaries and want to write single expression that returns these two dictionaries merged the update method would be what need if it returned its result instead of modifying dict in place update print none how can get that final merged dict in ...
wanted something similar but with the ability to specify how the values on duplicate keys were merged so hacked this out but did not heavily test it obviously this is not single expression but it is single function call def merge merge fn lambda merges two dictionaries non destructively combining values on duplicate ke...
QA
pros and cons of different approaches to web programming in python would like to do some server side scripting using python but am kind of lost with the number of ways to do that it starts with the do it yourself cgi approach and it seems to end with some pretty robust frameworks that would basically do all the job the...
ok rails is actually pretty good but there is just little bit too much magic going on in there from the ruby world would much prefer merb to rails personally use pylons and am pretty darn happy would say compared to django that pylons allows you to interchange ints internal parts easier than django does the downside is...
QA
how would you make comma separated string from list what would be your preferred way to concatenate strings from sequence such that between each two consecutive pair comma is added that is how do you map for instance to the cases and should be mapped to and respectively usually end up using something like join map lamb...
mylist would mystring join mylist this will not work if the list contains numbers as ricardo reyes suggested if it contains non string types such as integers floats bools none then do mylist join map str mylist
QA
how would you make comma separated string from list what would be your preferred way to concatenate strings from sequence such that between each two consecutive pair comma is added that is how do you map for instance to the cases and should be mapped to and respectively usually end up using something like join map lamb...
why the map lambda magic does not this work foo print join foo print join print join edit mark biek points out the case for numbers perhaps the list comprehension join str for in foo is more pythonic edit thanks for the suggestions will use the generator rather than the list comprehension in the future join str for in ...
QA
how would you make comma separated string from list what would be your preferred way to concatenate strings from sequence such that between each two consecutive pair comma is added that is how do you map for instance to the cases and should be mapped to and respectively usually end up using something like join map lamb...
do not you just want join obviously it gets more complicated if you need to quote escape commas etc in the values in that case would suggest looking at the csv module in the standard library https docs python org library csv html
QA
how would you make comma separated string from list what would be your preferred way to concatenate strings from sequence such that between each two consecutive pair comma is added that is how do you map for instance to the cases and should be mapped to and respectively usually end up using something like join map lamb...
unless am missing something join foo should do what you are asking for join join join edit and as jmanning points out join str for in foo is safer and quite pythonic though the resulting string will be difficult to parse if the elements can contain commas at that point you need the full power of the csv module as dougl...
QA
can someone explain all in python have been using python more and more and keep seeing the variable all set in different init py files can someone explain what this does
it is list of public objects of that module it overrides the default of hiding everything that begins with an underscore
QA
can someone explain all in python have been using python more and more and keep seeing the variable all set in different init py files can someone explain what this does
from an unofficial python reference wiki the public names defined by module are determined by checking the module namespace for variable named all if defined it must be sequence of strings which are names defined or imported by that module the names given in all are all considered public and are required to exist if al...
QA
how would you make comma separated string from list what would be your preferred way to concatenate strings from sequence such that between each two consecutive pair comma is added that is how do you map for instance to the cases and should be mapped to and respectively usually end up using something like join map lamb...
jmanning using list comprehension has the downside of creating new temporary list the better solution would be using itertools imap which returns an iterator from itertools import imap foo bar join imap str
QA
can the http version or headers affect the visual appearance of web page know would have thought the answer was obviously no as well but am experiencing strange situation where when view my site from our staging server it appears slightly larger than when view it from my local dev server have used charles to confirm th...
have you tried view zoom reset on both sites
QA
python packages import by class not file say have the following file structure app app py controllers init py project py plugin py if app controllers project py defines class project app py would import it like this from app controllers project import project would like to just be able to do from app controllers import...
you need to put from project import project in controllers init py note that when absolute imports become the default python you will want to add dot before the module name to avoid collisions with top level model named project from project import project
QA
where can find the time and space complexity of the built in sequence types in python have been unable to find source for this information short of looking through the python source code myself to determine how the objects work does anyone know where could find this online
if your asking what think your asking you can find them here page and on it is written around optimization techniques for python it is mostly big notation of time efficiencies not much memory
QA
is there python library for generating ico files am looking to create favicon ico files programatically from python but pil only has support for reading ico files
perhaps the following would work generate your icon image using pil convert the image to ico format using the python interface to imagemagick pythonmagick have not tried this approach the imagemagick convert command line program was able to convert png file to ico format so at least imagemagick supports the ico format
QA
is there python library for generating ico files am looking to create favicon ico files programatically from python but pil only has support for reading ico files
do not know if this applies for all cases but on winxp an ico can be bmp of size or just change the extension to ico from bmp and you are ready to go
QA
where can find the time and space complexity of the built in sequence types in python have been unable to find source for this information short of looking through the python source code myself to determine how the objects work does anyone know where could find this online
raymond hettinger does an excellent talk slides about python built in collections called core python containers under the hood the version saw focussed mainly on set and dict but list was covered too there are also some photos of the pertinent slides from europython in blog here is summary of my notes on list stores it...
QA
wacom tablet python interface if possible want to catch pressure sensitive input from wacom tablet in python are there any python libraries available that can do this
you could perhaps take look at the software described here it is gnome applet written in python from the web site the gnome wacom applet is small gnome panel applet that shows how much pressure is being applied to your wacom tablet by the current device clicking on the panel icon brings up dialog allowing you to select...
QA
is there python library for generating ico files am looking to create favicon ico files programatically from python but pil only has support for reading ico files
according to wikipedia modern browsers can handle favicons in png format so maybe you could just generate that alternatively the ico article describes the format
QA
analizing mips binaries is there python library for parsing binary data am working on utility which needs to resolve hex addresses to symbolic function name and source code line number within binary the utility will run on linux on though the binaries it analyzes will be for mips based embedded system the mips binaries...
do not know of any but if all else fails you could use ctypes to directly use libdwarf libelf or libbfd
QA
where can find the time and space complexity of the built in sequence types in python have been unable to find source for this information short of looking through the python source code myself to determine how the objects work does anyone know where could find this online
checkout the timecomplexity page on the py dot org wiki it covers set dicts lists etc at least as far as time complexity goes
QA
how to know whether window with given title is already open in tk ve writen little python script that just pops up message box containing the text passed on the command line want to pop it up only when the window resulting from previous call is not open from tkinter import import tkmessagebox root tk root withdraw todo...
believe you want if normal root state tkmessagebox showinfo key you join sys argv
QA
how would you make comma separated string from list what would be your preferred way to concatenate strings from sequence such that between each two consecutive pair comma is added that is how do you map for instance to the cases and should be mapped to and respectively usually end up using something like join map lamb...
peter hoffmann using generator expressions has the benefit of also producing an iterator but saves importing itertools furthermore list comprehensions are generally preferred to map thus would expect generator expressions to be preferred to imap foo bar join str bit for bit in foo bar
QA
pylons error mysql server has gone away hope this is not too obscure will ask the newsgroup if nobody knows here am using pylons python framework to serve simple web application but it seems to die from time to time with this in the error log mysql server has gone away did bit of checking and saw that this was because ...
think fixed it it is turns out had simple config error my ini file read sqlalchemy default url connection string here sqlalchemy pool recycle the problem is that my environment py file declared that the engine would only map keys with the prefix sqlalchemy default so pool recycle was ignored the solution is to simply c...
QA
why java and python garbage collection methods are different python uses the reference count method to handle object life time so an object that has no more use will be immediately destroyed but in java the gc garbage collector destroys objects which are no longer used at specific time why does java choose this strateg...
reference counting is particularly difficult to do efficiently in multi threaded environment do not know how you would even start to do it without getting into hardware assisted transactions or similar currently unusual atomic instructions reference counting is easy to implement jvms have had lot of money sunk into com...
QA
iterate over subclasses of given class in given module in python given module and class how can iterate or generate list of all subclasses of that exist in module
can suggest that neither of the answers from chris atlee and zacherates fulfill the requirements think this modification to zacerates answer is better def find subclasses module clazz for name in dir module getattr module name try if clazz and issubclass clazz yield name except typeerror pass the reason disagree with t...
QA
which version of python to use for maximum compatibility if was going to start an open source project using python what version should use to ensure that the vast majority of users can use it on their system am the kind of person who quickly jumps to the next version which will do when python comes out but many people ...
have not seen system with less than installed for some time mostly is installed by default for most os use now is just on an older solaris machine linux distros tend to have as does os iirc has lot of the features does but usable only with from future import
QA
which version of python to use for maximum compatibility if was going to start an open source project using python what version should use to ensure that the vast majority of users can use it on their system am the kind of person who quickly jumps to the next version which will do when python comes out but many people ...
as python is in kind of an transition phase towards python with breaking backward compatibility do not think it is good idea to go python only based on the time line there will be at least one or two following releases of the series after in october beside not having python available on your target platforms it will ta...
QA
django print url of view without hardcoding the url can print out url admin manage products add of certain view in template here is the rule want to create link for manage products add create object model product post save redirect would like to have manage products add in template without hardcoding it how can do this...
if you use named url patterns you can do the follwing in your template url create object
QA
django print url of view without hardcoding the url can print out url admin manage products add of certain view in template here is the rule want to create link for manage products add create object model product post save redirect would like to have manage products add in template without hardcoding it how can do this...
the preferred way of creating the url is by adding get absolute url method to your model classes you can hardcode the path there so you at least get closer to following the kiss philosophy you can go further by utilizing the permalink decorator that figures the path based on the urls configuration you can read more in ...
QA
which version of python to use for maximum compatibility if was going to start an open source project using python what version should use to ensure that the vast majority of users can use it on their system am the kind of person who quickly jumps to the next version which will do when python comes out but many people ...
you can use different versions of python on each machine coding something new would not use anything less than python you can do apt get install python on stock debian stable for windows do not really worry about it it is very easy to install the python msi if the users cannot be bothered to do that you can deploy an e...
QA
how do you set up python wsgi server under iis work in windows environment and would prefer to deploy code to iis at the same time would like to code in python having read that iis can run fastcgi application went to the iis site where it describes in detail how to get php up and running but not much about anything els...
there should not be any need to use fastcgi there exists isapi extension for wsgi
QA
django print url of view without hardcoding the url can print out url admin manage products add of certain view in template here is the rule want to create link for manage products add create object model product post save redirect would like to have manage products add in template without hardcoding it how can do this...
you can use get absolute url but that will only work for particular object since your object has not been created yet it will not work in this case you want to use named url patterns here is quick intro change the line in your urls py to manage products add create object model product post save redirect create product ...
QA
is there way to attach debugger to multi threaded python process am trying to debug deadlock in multi threaded python application after it has locked up is there way to attach debugger to inspect the state of the process edit am attempting this on linux but it would be great if there were cross platform solution it is ...
what platform are you attempting this on most debuggers allow you to attach to running process by using the process id you can either output the process id via logging or using something like task manager once that is achieved it will be possible to inspect individual threads and their call stacks edit do not have any ...
QA
generator expressions vs list comprehension when should you use generator expressions and when should you use list comprehensions in python generator expression for in range list comprehension for in range
use list comprehensions when the result needs to be iterated over multiple times or where speed is paramount use generator expressions where the range is large or infinite
QA
generator expressions vs list comprehension when should you use generator expressions and when should you use list comprehensions in python generator expression for in range list comprehension for in range
iterating over the generator expression or the list comprehension will do the same thing however the list comprehension will create the entire list in memory first while the generator expression will create the items on the fly so you are able to use it for very large and also infinite sequences
QA
generator expressions vs list comprehension when should you use generator expressions and when should you use list comprehensions in python generator expression for in range list comprehension for in range
john answer is good that list comprehensions are better when you want to iterate over something multiple times however it is also worth noting that you should use list if you want to use any of the list methods for example the following code will not work def gen return something for something in get some stuff print g...
QA
what are the advantages of packaging your python library application as an egg file have read some about egg files and have noticed them in my lib directory but what are the advantages disadvantages of using then as developer
from the python enterprise application kit community eggs are to pythons as jars are to java python eggs are way of bundling additional information with python project that allows the project dependencies to be checked and satisfied at runtime as well as allowing projects to provide plugins for other projects there are...
QA
what are the advantages of packaging your python library application as an egg file have read some about egg files and have noticed them in my lib directory but what are the advantages disadvantages of using then as developer
egg files are basically nice way to deploy your python application you can think of it as something like jar files for java more info here
QA
what are the advantages of packaging your python library application as an egg file have read some about egg files and have noticed them in my lib directory but what are the advantages disadvantages of using then as developer
eggs are pretty good way to distribute python apps think of it as platform independent deb file that will install all dependencies and whatnot the advantage is that it is easy to use for the end user the disadvantage are that it can be cumbersome to package your app up as egg file you should also offer an alternative m...
QA
glade or no glade what is the best way to use pygtk have been learning python for while now with some success even managed to create one or two simple programs using pygtk glade the thing is am not sure if the best way to use gtk with python is by building the interfaces using glade was wondering if the more experience...
use gtkbuilder instead of glade it is integrated into gtk itself instead of separate library the main benefit of glade is that it is much much easier to create the interface it is bit more work to connect signal handlers but have never felt that matters much
QA
which version of python to use for maximum compatibility if was going to start an open source project using python what version should use to ensure that the vast majority of users can use it on their system am the kind of person who quickly jumps to the next version which will do when python comes out but many people ...
python or if you can live without the many modules that were added datetime csv logging optparse zipimport are not using ssl and are willing to add boilerplate for true false added decorators generator expressions reversed sorted and the subprocess and decimal modules although these are all nice it is easy to write pyt...
QA
embedding remote python she will in an application you can embed the ipython she will inside of your application so that it launches the she will in the foreground is there way to embed telnet server in python app so that you can telnet to certain port and launch remote ipython she will any tips for redirecting the inp...
python includes telnet client but not telnet server you can implement telnet server using twisted here is an example as for hooking these things together that is up to you
QA
how can render tree structure recursive using django template have tree structure in memory that would like to render in html using django template class node name node name children there will be some object root that is node and children is list of nodes root will be passed in the content of the template have found t...
django has built in template helper for this exact scenario https docs djangoproject com en dev ref templates builtins unordered list
QA
embedding remote python she will in an application you can embed the ipython she will inside of your application so that it launches the she will in the foreground is there way to embed telnet server in python app so that you can telnet to certain port and launch remote ipython she will any tips for redirecting the inp...
think you should base your server class on the socketserver class from the standard library you will need to write requesthandler to read and echo input but lot of the heavy lifting is already done for you you can use the threadingmixin to make the server multi threaded very easily
QA
python web application framework for tight db gui coupling am firm believer of the heretic thought of tight coupling between the backend and frontend want existing implied knowledge about backend to be automatically made use of when generating user interfaces if varchar column has maximum with of characters there guis ...
turbogears currently uses sqlobject by default but you can use it with sqlalchemy they are saying that the next major release of turbogears will use sqlalchemy by default
QA
what is tuple useful for am learning python for class now and we just covered tuples as one of the data types read the wikipedia page on it but could not figure out where such data type would be useful in practice can have some examples perhaps in python where an immutable set of numbers would be needed how is this dif...
like this explanation basically you should use tuples when there is constant structure the st position always holds one type of value and the second another and so forth and lists should be used for lists of homogeneous values of course there is always exceptions but this is good general guideline
QA
project structure for google app engine started an application in google app engine right when it came out to play with the technology and work on pet project that had been thinking about for long time but never gotten around to starting the result is bowlsk however as it has grown and features have been added it has g...
am not entirely up to date on the latest best practices et cetera when it comes to code layout but when did my first gae application used something along your second option where the code and templates are next to eachother there was two reasons for this one it kept the code and template nearby and secondly had the dir...
QA
python web application framework for tight db gui coupling am firm believer of the heretic thought of tight coupling between the backend and frontend want existing implied knowledge about backend to be automatically made use of when generating user interfaces if varchar column has maximum with of characters there guis ...
know that you specificity ask for framework but thought would let you know about what get up to here have just undergone converting my company web application from custom in house orm layer into sqlalchemy so am far from an expert but something that occurred to me was that sqlalchemy has types for all of the attributes...
QA
how do implement pre commit hook script in svn that calls dos unix to validate checked in file was wondering if anyone here had some experience writing this type of script and if they could give me some pointers would like to modify this script to validate that the check in file does not have carriage return in the eol...
what exactly are you trying to do of course there are numerous places to learn about svn pre commit hooks here here and in the red book but it depends what you are trying to do and what is available on your system can you be more specific