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)

1
vote
2answers
24 views

Empty except block vs. huge except block

Which of these is easier to read? An empty except block: try: foo = do_foo() except FooError: pass # see below else: return do_bar(foo) # Recover from the FooError (long, complicated) ...
3
votes
3answers
307 views

Why do python generators and functions share the “def” keyword?

Consider the following: def some_function(): return 1 def some_generator(): yield 1 In the code above, some_function is a function, while some_generator is a generator. They look quite ...
0
votes
0answers
15 views

Best strategy for converting change in longitude and latitude to north, south, east, west in degrees

This is not a class assignment but a conceptual question I'm struggling with for a personal project. I need to convert a large paired group of long and lat coordinate values that show a ...
2
votes
1answer
155 views

Any reasons NOT to write self testing Python code?

Whilst writing tests I was giving considerable thought to the question of how to ensure I have tests for every class in my application. It occurred to me that maybe I should just put the test code ...
1
vote
1answer
54 views

Allow user to enter DSL, rules or code?

I have a python library that allows me to define rules by chaining inputs and outputs of functions ( producer(grep(count( [print(),log() ] ))) This functions define a pipeline from left to right. ...
-2
votes
3answers
100 views

How to manage a large list of distinct numbers

I have a list of around 2 billion distinct numbers stored in memory for some computation. Currently, every time I need to add a new entry I have to search the entire list for a potential duplicate. ...
-2
votes
1answer
42 views

How to program GUI applications in python without additional modules [on hold]

I want to program GUI in python but I don't want to use preexisting modules like pygame or tkinter. Edit: What I can do is program GUI in C, Is it possible to link my C programs with Python?
0
votes
0answers
10 views

I want use “isinstance” to judge what type object people input from keyboard [migrated]

This is my code num = input() if not isinstance(num,int): print("wrong input") num = input() However if I type letters from keyboard,the computer gives this error: please input a num q ...
-1
votes
0answers
22 views

Problem with codeacademy python exercise [on hold]

Write a function called censor that takes two strings, text and word, as input. It should return the text with the word you chose replaced with asterisks. def censor(text, word): result = [] ...
-6
votes
0answers
48 views

Can I balance a full-time job and a programming internship? [closed]

Though I didn't get my degree in Comp Sci, I studied in Finance (BA) and Economics (MS) and have picked up programming as a hobby that I'd really like to incorporate in my career. My initial thought ...
-4
votes
0answers
69 views

Do you think it’s worth it to learn bash scripting in 2015? [closed]

I really am interested in getting a Linux job, so I started learning bash scripting on my own, but, I did a search recently, and found that a lot of people recommended using Perl or Python, because ...
4
votes
1answer
50 views

Should I use exceptions to control the range of parameters in Python?

For example for the following method signature: def genClusters(n_clusters, n_nodes, cluster_distribution): n_clusters should be an integer of more than 1. n_nodes should be an integer of more ...
0
votes
0answers
18 views

moving Data mining model from “lab” to production environment

I am designing the architecture of an analytics system . I have a data mining ensemble model developed in scikit learn . I want to move this to the production environment so the new incoming data can ...
1
vote
1answer
24 views

Is there a standard project metadata / dependency file for Python?

In my Node.JS projects, I save my project metadata into package.json: dependencies, version number, author, description, and so on. This makes it so anyone can clone my project and run npm install to ...
0
votes
0answers
11 views

Disappearing text in GUI prompt for Python Tkinter [migrated]

I am currently writing a small GUI in Linux for teaching younger member of my club how to do version control. I am using python Tkinter lib. I have made a text space to insert text and have placed an ...
0
votes
0answers
24 views

Persist data downloaded by Celery workers

I'm working in a tool that downloads tweets from Twitter to process them later. For this purpose I'm using Celery with RabbitMQ, sending task with the keywords that must be tracked by the workers. My ...
0
votes
0answers
25 views

Improve communication between controller and trackers in a Twitter fetcher tool using RabbitMQ or Apache Flume

I've been working for a time with some researches developing a tool to fetch tweets from Twitter and process them in some way. The first prototype "worked" but became a pain as we used sockets to ...
2
votes
3answers
332 views

Multiple users using the same script for their websites

I'm working on a project, I have a question regarding the architecture: Say I have a many python scripts on my server and there's main.py which contains all the classes. And there's a script called ...
-4
votes
0answers
14 views

How do I debug a python multiple-sentence generator? [migrated]

I made my own Python code like this: import random # nouns----------------------------------------------------------------------------------------------------------------- nouns = 'noun1 noun2 noun3 ...
0
votes
1answer
32 views

Should I have all models done before I syncdb?

I'm not sure if I want to add more attributes to my models or create another model. I've coded up to the point where I need to syncdb to start using some data in the site, but I'm hesitant to do it. ...
0
votes
0answers
31 views

Is there a standard practice on making a modular Python script?

I wrote a Python script for PIA here: pia-auto-login.py However, I need to make it more modular so that it does the OpenVPN changes from this script. Then I want to create two more packages (at ...
0
votes
1answer
57 views

Using a bytearray rather than a string to store password in memory

Using a bytearray datatype to store a password (in memory) has an advantage over using a string datatype for a password in that a bytearray is mutable and can be overwritten with 0x00 values when the ...
0
votes
1answer
56 views

Facing MemoryError in Python

I wrote a program to find prime factors of a number. When I give a large number(600851475143) as input, MemoryError pops up. Below is the code: def fact(a): factors = [] for i in ...
8
votes
6answers
274 views

why empty function are needed

I started learning python and I am wondering why empty function are needed in a programming language e.g. in python: def empty_func(): pass even in shell scripts empty function empty functions ...
94
votes
14answers
15k views

Is it always a best practice to write a function for anything that needs to repeat twice?

For myself, I can't wait to write a function when I need to do something more than twice. But when it comes to the things that only appear twice, it's a bit more tricky. For code that needs more than ...
1
vote
1answer
55 views

Repeating groups of arguments with argparse

Let's say that I want to enter info about multiple users from the command line AND that each user has multiple data associated with it. Is it possible (syntactically permissible) to use argparse to ...
5
votes
0answers
89 views

How to write __getitem__ cleanly? [migrated]

In Python, when implementing a sequence type, I often (relatively speaking) find myself writing code like this: class FooSequence(collections.abc.Sequence): # Snip other methods def ...
0
votes
1answer
137 views

How would a modern website like Reddit divide up its website into Django apps? [closed]

Django uses apps to divide projects into manageable and reusable chunks. All examples in tutorials use polls or articles in unrelatable circumstances. In a modern example like Reddit (or even Amazon ...
-1
votes
1answer
47 views

Send Emails Via APIs or Code?

I am Using SendGrid to Send Emails to my Users. There are two ways to send emails via SendGrid. 1 - Via APIs 2 - Via Program/Code I want to know which one is More Secure and efficient way. I am ...
0
votes
4answers
228 views

Identifying user of a webapp

For a small webapp I want to be able to identify a user. The issue is, if the user cheats in some manner, I want to be able to forbid him the usage of my application. I already have done extensive ...
5
votes
1answer
142 views

How to efficiently store big time series data?

I need to store and to be able to query some very large amounts time series data. Properties of the data are as follows: number of series : around 12.000 (twelve thousand) number of data points, ...
1
vote
1answer
30 views

Splitting single Class into multiple Classes

I am writing automated test scripts with Selenium Webdriver (Python) and I try to follow the correct programming practices, specifically the Object Oriented methodologies, where possible. At the ...
0
votes
0answers
69 views

Best practices to parse a log file using Python

I'm writing a Python tool to parse a log file from game server. The log file is of format: ms:classname::id::method::arg1::arg2.... There are a lot of classes, and a lot of methods for each class, ...
1
vote
0answers
111 views

Why does this code work? [closed]

I'm taking Udacity's Intro to Computer Science course and one of the quizzes had me create a function that takes in two dates and checks whether the first date is before the second. I first wrote the ...
0
votes
0answers
54 views

How to put a .py file on a web host and use it in the command prompt?

So I have a python file that runs a method when it opens a file. Ie. my python.py file opens test.txt and puts it data into another file. The test.txt file is on my local PC, but I want the ...
0
votes
0answers
6 views

Why do I get this error in Python? [migrated]

I’m making a program where if a user enters text it will convert any caps into lowercase: def lowerChar(char): if ord(char) >= 65 and ord(char) <= 90: char = int(ord(char)) + 32 ...
6
votes
2answers
199 views

Version control for code that contains student exercises

I have a fairly substantial Python project that I have developed as an educational endeavor. The version of the code that shall be given to students has exercises throughout, in the form of code that ...
1
vote
3answers
76 views

Using higher order functions to apply m out of M filter's and then transform data of size n?

Total no: of filters possible is M . User can select m filters where m <= M . A typical example is files from a folder , he could say modified between so and so date , start with so and so and so ...
0
votes
0answers
43 views

Python - Flask controller structure

This is my first python application (I have some experience in Java/groovy-grails), and therefore I am not confident of the application structure I should be following. My application has two ...
1
vote
1answer
113 views

Does dynamically generating classes in python affect readability/performance?

I have a set of classes that represent different objects (tables in a database): class ObjA: # some class specific attributes and methods def refresh(self): # implementation ...
3
votes
3answers
353 views

How to use multiple programming languages together in the same program? [closed]

Such a simple question, but I have not found a reasonable answer to this. I currently program in Python, an interpreted language. I always hear of people using multiple languages in the same program? ...
1
vote
1answer
229 views

From which point does it become dangerous to keep going as the sole developer on a project? [duplicate]

I'm working at a company where the management wants to capitalise on consulting experience to offer quality software to their (already existing) customers, and expand from that to become one day ...
0
votes
2answers
85 views

How early does a hashable type need to become immutable?

Suppose I have a class that looks vaguely like this: class Foo(object): _value = None # XXX: see below def __init__(self, value): self._value = value @property def ...
2
votes
3answers
74 views

How do I deal with imported modules in GPL?

I wish to release a non-commercial python application under GPL3 in both source and (PyInstaller) executable form. I'm struggling to find a consistent answer to the problem of imported modules. Can I ...
3
votes
1answer
91 views

How should I represent composeable, associative computations to be repeatedly applied to units of data?

Spoiler My question is the following: Are there any design patterns for representing chainable functions that are for the problem described below? High-Level Decription of the Process I'm ...
0
votes
2answers
87 views

Is it ok to access private members while doing same class comparison?

I am writing a class which basically is a wrapper around a dictionary with some extra functionality. This dictionary is stored as protected member _store. Now I am writing a __eq__ method to compare ...
0
votes
1answer
51 views

Why do objects created with no assignment not generate a syntax error in Python?

While working on a Python project, I realized that during my editing I had left a string floating around in the middle of my code and it didn't generate an error. For example, these few lines execute ...
-1
votes
1answer
66 views

Python recipe question: Use of **kwds instead of specific named argument in itertools recipe [closed]

The function definition below comes from the itertools recipes page (https://docs.python.org/2/library/itertools.html#recipes). def random_product(*args, **kwds): "Random selection from ...
2
votes
1answer
117 views

Python Open Source Development

I am looking to contribute to some Python projects on Github, and I am looking for a bit of clarification on the mechanics of doing this effectively. As I understand it, the typical workflow is as ...
0
votes
1answer
45 views

How can I determine which version of Python introduced a particular module to the std lib? [closed]

Is there a single timeline-style resource available showing the history of the modules available in different versions of Python? I'd like to, for instance, easily determine which version of Python ...