Tagged Questions

Python is a dynamic, high-level language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules, exceptions, had an extensive standard module library. Python can also be embedded in other ...

learn more… | top users | synonyms (1)

0
votes
1answer
41 views

how python updates references to variables

For this while loop below. It is clear how the v1,v2,v3 are updated to new data objects based on the equation. But I do not understand how u1,u2,u3 retains the original values of v1,v2,v3.Can someone ...
-3
votes
0answers
12 views

while creating Virtual Environment Project in Python I'm not able to run server in Python Please help me out to figure the error [on hold]

After Creating the virtualenv in python and craeted a project called myproject and in that django has been installed and then tryed to run the manage.py to start sever it is not running it is ...
0
votes
0answers
22 views

how to test a generator with unittest?

I have programmed a small iterator in Python: class anything(): def __init__(self): self.i=1 def __iter__(self): return self def next(self): if self.i>100: ...
-3
votes
0answers
23 views

Python MySQLdb vs mysql-connector-python [on hold]

Could anyone who is experienced with both MySQLdb and mysql-connector-python talks about the pros and cons of using each of them to connect to MySQL/MariaDB through Python? I believe it would be ...
0
votes
0answers
29 views

Minimizing Downtime With Upgrades For 3rd Party Products [migrated]

I am currently maintaining a Review Board server (https://www.reviewboard.org/) and one of the big pain points is scheduling upgrades. Currently the process is: Take the server down and send all ...
-3
votes
0answers
58 views

Python algorithms for poker hands? [on hold]

I am in the middle of writing a Texas Hold'Em poker program in Python and need some algorithms. I'm sure I can write these but I'd like to see if someone already has something similar to this. NOTE I ...
0
votes
0answers
51 views

Naming self or this something else, a good idea?

I'm finding that my code becomes more readable when I make a local reference to this/self, and/or call it something that makes sense in the context. "self" or "this" doesn't really indicate what kind ...
0
votes
0answers
20 views

How to stop connecting to a server after n unsuccessful attempts? [migrated]

Here is the problem. I am trying to connect to a server. If the connection goes through, then print an apt message. If the connection does not go through, try for a total of n times. And quit after ...
-4
votes
0answers
45 views

how couldnI write a python program to calculate fourier series [on hold]

while I am researching wave function, I found out there is a way to calculate the result by Fourier Series. But I have little experience with python. can anyone show me how to write the python program ...
1
vote
2answers
101 views

Python: Object initialised inside a Class?

Is possible and, if so, common practice to initialize an object inside a class in Python? self.field = Class()
3
votes
2answers
2k views

Every function is a closure?

Wikipedia says, that closure - is a function, which has an access to variables, declared outside of the function. There is even an example: function startAt(x) function incrementBy(y) ...
0
votes
1answer
82 views

Handling the process of large-scale lists [on hold]

What are the efficient ways to process huge lists (+10 millions), and things to consider while manipulating huge lists. First question, when should I use recursion, and when I shouldn't. In both ...
-2
votes
0answers
32 views

How can I un-draw a batch or switch from one batch to another or should I do something else? [closed]

So I've been pondering on this since last night. Say I made a menu made out of text labels and put it in a batch to be drawn under @window.event. I want it to go away after I make a selection, how do ...
0
votes
0answers
5 views

Pylab: Why does script run from Canopy command prompt but not Window's Powershell? [migrated]

When I try and run the Python script below in the Canopy 64-bit command prompt it works but when I try it on the standard Window's Powershell it gives me an ImportError (see image). I ran the files ...
1
vote
2answers
24 views

How to handle configuration of Python modules, especially when used standalone and in frameworks like Django

I am trying to package a Python module for pip, following the guide here. One area I would like feedback on is best practices or convention for making my module configurable. The module is a library ...
1
vote
1answer
41 views

Is this type of data insertion safe and can stop sql injection in Python?

I am learning Database connection from MySQL Connector/Python Developer Guide. This is the code I am using to insert data: conn = mysql.connector.connect(user="user", password="password", ...
-4
votes
0answers
53 views

Programming languages must have multiple symbols allowed for brackets. What do you think? [closed]

How many of you find it annoying and confusing when there are too many brackets in the code. For example, something like this. logData.map(lambda x: (int(x[0]), int(x[1]))) What I propose, is to ...
1
vote
1answer
95 views

Why is a python package more perfomant as zip?

I have read the following text in the setuptools documentation: For maximum performance, Python packages are best installed as zip files. ...
0
votes
1answer
104 views

How do different technologies connect to form a web stack? [closed]

I am a little confused, is it possible to implement a front end using common languages like html, css and javascript and then do server side processing using a language of your choice, say python or ...
0
votes
0answers
13 views

Python: algorithm for describing chess positions [migrated]

I have an interesting problem with my chess application. The application reads PGN files, and at any time while viewing a game from the file, the function below, when called, iterates over the ...
-2
votes
0answers
53 views

Selling the idea of using Python vs Java for offline batch jobs [duplicate]

I need to make a case to my team why we should expand our technology spectrum onto Python. We currently use Java with JBoss and JSF/PrimeFaces for our mission critical, user-interactive web ...
1
vote
0answers
70 views

The Python module-as-singleton hack

I've seen (and once used) this idiom a few times in Python: # At the end of a module: if __name__ == '__main__': main() # or whatever your entry point looks like, this line isn't important else: ...
1
vote
2answers
64 views

Is it safe to catch ImportError when trying to import optional modules?

I usually see this pattern at least once in every Python project I work on. For example, in a Django project, this is often added at the bottom of the base settings file: try: from .local_settings ...
0
votes
3answers
117 views

Socket Connecting to Large number of IPs

I have a text file of ~600 CIDR notation IP blocks which, when expanded, amount to ~17.5M IP addresses. I need to socket connect to each one. If it connects, I add it to a "live" list, if it returns ...
4
votes
2answers
128 views

In Python, is there any difference (apart from a few listed exceptions) between classes and dictionaries?

My logic goes like this: def A(val): return {'a':val} print(A(7)['a']) is the same as class A: def __init__(self, val): self.a = val print(A(7).a) Obviously, there are problems ...
16
votes
3answers
912 views

Should I pass in filenames to be opened, or open files?

Suppose I have a function that does things with a text file - for example reads from it and removes the word 'a'. I could either pass it a filename and handle the opening/closing in the function, or ...
0
votes
2answers
80 views

Print Statements Inside Function Or Before Calling It? [closed]

I have a script which different people may use. I have print statements so people can follow along what the script is doing, and if it breaks where it went wrong, and if a certain step takes a long ...
1
vote
0answers
17 views

How should private dependency links be handled in setup.py

At work we use a private pypi server. This pypi server is specified as a dependency link: ... from setuptools import setup config = ConfigParser.ConfigParser() rc = ...
0
votes
1answer
29 views

using one database connection across multiple functions in python

whats the best way to go about this in python? I have a number of like so def test1() .... code ..... def test2() .... code ..... def test3() .... code ..... how could I create one ...
1
vote
0answers
86 views

Python: Why are int & list function parameters differently treated? [migrated]

We all know the dogma that global variables are bad. As I began to learn python I read parameters passed to functions are treated as local variables inside the funktion. This seems to be at least half ...
0
votes
3answers
114 views

OOP: relying on protected properties in a class-subclass contract

I'm coding in Python, but the question seems independent of programming language. I have a class that represents some system check: class Check: @abstractmethod def run() """ You have to ...
1
vote
1answer
61 views

graph implementation in PYthon

I have found the following implementation of a Flow algorithm in Python: class Edge(object): def __init__(self, u, v, w): self.source = u self.sink = v self.capacity = w ...
-2
votes
0answers
54 views

Measuring Damerau-Levenshtein distance in Python

I'm working on a searching in dictionary. I want to check all words from the dictionary whether they have Levenshtein (or better Damerau-Levenshtein) distance lower than (for example) 2 compared to ...
-5
votes
0answers
43 views

Why doesn't my program see the # boundary condition? [migrated]

There is the program I have been writing. All the variables have been defined in the main function. When I compile, it does not give me errors, but it just does seems to see the #boundary condition ...
0
votes
1answer
68 views

Is there a canonical way to cache instance methods in python?

I have some computationally intensive functions in my python script that I would like to cache. I went looking for solutions on stack overflow and found lots of links: ...
-3
votes
1answer
66 views

Understanding searching through dicts in python [closed]

I'm trying to understand the differences between dict, dict.items and dict.iteritems. I know that items returns a list of all the items, while iteritems returns an iterator, which for large lists can ...
0
votes
1answer
45 views

No repeated coordinates in random walker ensemble

i'm simulating an ensemble of random walkers in 2D in python, I set [x,y] coordinates of my walkers to be gaussian in a 2D grid, then use a rand array of -1 and +1 to move up down left right: N=20 ...
0
votes
0answers
21 views

Python - Function - Argument said to be “undefined” [migrated]

I'm currently taking a Python course, and got to the chapter in our book that talks about functions. (Please note, this is my first time learning any programming.) One of the exercises I'm working on ...
2
votes
2answers
118 views

How much should I break up my unit tests?

I recently learned about unit tests and TDD and have started going back to add unit tests to my code (and thank god, it's proven that some things I've written are much more broken than I thought). ...
1
vote
1answer
201 views

Should I couple these classes?

I am programming in Python. I have several complicated/hard-to-understand XML files that describe the structure of an election. I am trying to write a python wrapper that makes it easy to access this ...
1
vote
1answer
76 views

Transferring information between a web server and a Python backend?

I have been Googling my problem but haven't been able to come up with anything; here's the situation: I have a PHP / MySQL website hosted with 1and1.com. I also have a Python program that runs on a ...
0
votes
1answer
31 views

Plugins and exporting an API between python scripts

I've got a python script, which should read a subdirectory and make all the scripts within it callable like this: python mainscript.py subscript arguments I've figured out most of the details but ...
1
vote
2answers
154 views

How-To: a browser based, real time, shared memory inspection/debugger application [closed]

Background: I have a C application running under Linux utilizing shared memory. I also have a debugger written in Python that can link to said shared memory and access individual variable values of ...
1
vote
0answers
29 views

Breaking a table over multiple lines in Sphinx

Lets say I have the following function with a docstring: def foo(*args): """ do some fooness +----------------------------+----------------------------------------------------+ | ...
2
votes
1answer
135 views

What exactly is this Python statement doing?

I'm trying to port a very basic dual contouring algorithm written in Python (here) to C++. I'm not a Python programmer so some of the language syntax is a bit foreign to me. Specifically, this block ...
-3
votes
2answers
48 views

How to perform deferred tasks in backend [closed]

Actually the problem is very common. Let me describe this by example. Imagine you have a web service where users register and pay for some gold status. There is expiration date. The question is how to ...
1
vote
4answers
122 views

How to clean up nested try/except/else?

When writing code, I often want to do something like this: try: foo() except FooError: handle_foo() else: try: bar() except BarError: handle_bar() else: ...
3
votes
1answer
88 views

Seeking Guidance on Thread Safe Scripting

I am trying to write a script that will take multiple paths to files on various servers, search them all simultaneously, and return a single list of results to a user. Initially, I was just using ...
0
votes
0answers
34 views

Advice on which approach to follow for sandboxing the input in an intentional “vulnerable” web app (sandbox in python) [duplicate]

my question is about which is the best approach/practice on building a "sandbox mechanism" in Python in a web application. The app will provide intentional vulnerable scenarios, and the user has to ...
4
votes
3answers
517 views

How to avoid large function arity / exposure of underlying implementation

Currently reading Clean Code, and the authors seem to imply that any function with an arity greater than 3 should be avoided at all costs. I am unfortunately running into an issue where I am faced ...