I’m working on a Python library that interfaces with a web service API. Like many web services I’ve encountered, this one requests limiting the rate of requests. I would like to provide an optional parameter, limit, to the class instantiation that, if provided, will hold outgoing requests until th…
Tag: python
Does Python have a ternary conditional operator?
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. Is there a ternary conditional operator in Python? Answer Yes, it was added in version 2.5. The expression syntax …
How do I parse a string to a float or int?
How can I convert a str to float? How can I convert a str to int? For the reverse, see Convert integer to string in Python and Converting a float to a string without rounding it. Please instead use How can I read inputs as numbers? to close duplicate questions where OP received a string from user input and im…
What are the differences between Perl, Python, AWK and sed? [closed]
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, …
What is the recommended way to use Vim folding for Python code
I am interested in enabling code folding in Vim for Python code. I have noticed multiple ways to do so. Does anyone have a preferred way to do Python code folding in Vim? I.e, Do you have a particular Vim plugin that you use and like? Do you use manual folding or do you place markers in comments? Any other
Printing all instances of a class
With a class in Python, how do I define a function to print every single instance of the class in a format defined in the function? Answer I see two options in this case: Garbage collector This has the disadvantage of being very slow when you have a lot of objects, but works with types over which you have no
Running unit tests on nested functions
I come from the Java world, where you can hide variables and functions and then run unit tests against them using reflection. I have used nested functions to hide implementation details of my classes so that only the public API is visible. I am trying to write unit tests against these nested functions to make…
Currency formatting in Python
I am looking to format a number like 188518982.18 to £188,518,982.18 using Python. How can I do this? Answer See the locale module. This does currency (and date) formatting.
Python library to modify MP3 audio without transcoding
I am looking for some general advice about the mp3 format before I start a small project to make sure I am not on a wild-goose chase. My understanding of the internals of the mp3 format is minimal. Ideally, I am looking for a library that would abstract those details away. I would prefer to use Python (but co…
Validating with an XML schema in Python
I have an XML file and an XML schema in another file and I’d like to validate that my XML file adheres to the schema. How do I do this in Python? I’d prefer something using the standard library, but I can install a third-party package if necessary. Answer I am assuming you mean using XSD files. Su…