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
0answers
222 views

Benefits of using object document mapping (ODM)

I am creating a web app on Flask and was planning to use mongodb. Most of the examples using this stack that I've come across have used an ODM of some kind and was wanting to figure out whether or not ...
0
votes
0answers
16 views

Question on Multiprocessing With Pymongo and Bulk Inserts

I would like to use the multiprocessing library to speed up the time it takes to insert data values into my mongo database. I found from the following resource: ...
-2
votes
0answers
24 views

Installment of Python 2.7.9 and 3.4.2 & Recommended Learning Source [on hold]

I am an undergraduate (sophomore) with double majors in microbiology and mathematics. I just started a research project on the computational biology that uses both Python and MATLAB; I see that most ...
0
votes
1answer
30 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 ...
0
votes
2answers
63 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) ...
4
votes
3answers
328 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 ...
8
votes
6answers
279 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 ...
2
votes
2answers
700 views

Front-end structure of large scale Django project

Few days ago, I started to work in new company. Before me, all front-end and backend code was written by one man. As you know, Django app contains two main directories for front-end: /static - for ...
51
votes
7answers
33k views

Why use try … finally without a catch clause?

The classical way to program is with try ... catch. When is it appropriate to use try without catch? In Python the following appears legal and can make sense: try: #do work finally: #do ...
21
votes
4answers
23k views

Is Python Interpreted or Compiled?

This is just a wondering I had while reading about interpreted and compiled languages. Ruby is no doubt an interpreted language, since source code is compiled by an interpreter at the point of ...
1
vote
1answer
234 views

Merge two different API calls into One

I have two different apps in my django project. One is "comment" and an other one is "files". A comment might save some file attached to it. The current way of creating a comment with attachments is ...
2
votes
1answer
167 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 ...
-2
votes
3answers
102 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. ...
1
vote
1answer
56 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
2answers
2k views

Why doesn't Python have a “flatten” function for lists?

Erlang and Ruby both come with functions for flattening arrays. It seems like such a simple and useful tool to add to a language. One could do this: >>> mess = [[1, [2]], 3, [[[4, 5]], 6]] ...
-2
votes
1answer
47 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?
1
vote
1answer
32 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
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
23 views

Problem with codeacademy python exercise [closed]

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
52 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
75 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
20 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
25 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 ...
2
votes
3answers
333 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 ...
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 ...
95
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 ...
-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
33 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
32 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
59 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 ...
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
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 ...
0
votes
4answers
229 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 ...
1
vote
1answer
58 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 ...
1
vote
3answers
139 views

the perils of using eval() for dynamic object creation — is this a valid argument in a consenting-adults culture?

I've read on stackoverflow explicit warnings against using eval() to create objects. The reason that seems to be given is that malicious code could be injected and blindly created objects could ...
0
votes
1answer
138 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 ...
5
votes
1answer
144 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
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 ...
14
votes
7answers
4k views

Would Python be too slow for client-side use in Browsers?

I've heard the statement that Python would be too slow to be of any use in browsers. I reckon Javascript is only superior in this aspect because of companies like Google who need it fast (and made it ...
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, ...
29
votes
5answers
17k views

'import module' vs. 'from module import function'

I have always been using this method: from sys import argv and use argv with just argv. But there is a convention of using this: import sys and using the argv by sys.argv The second method ...
1
vote
0answers
112 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 ...
17
votes
4answers
2k views

Are there any negative side effects of splitting up large modules? [closed]

I was browsing a github project and found this module which has more than 10 thousand lines. Is it a common practice to have that much code in a single module? It seems to me that this should be ...
-2
votes
3answers
1k views

Is there any way to use Python to replace Flash for in browser animation, gaming, whatever? [closed]

Is there any way to use Python to replace Flash for in browser animation, gaming, webapps, whatever? Pretty straight-forward IMHO. Does anyone know how to do this?
0
votes
1answer
54 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 ...
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 ...