Tagged Questions
0
votes
1answer
17 views
CSV file writing error. python
I made code working previously pasted .
import serial
import csv
import os
import time
def main():
pass
if __name__ == '__main__':
main()
COUNT=0
ser=serial.Serial()
ser.port=2
...
3
votes
1answer
31 views
Python 3.3 doesn't work properly on OS X Maverics
I installed python 3.3 in my new Macboook Pro Retina Late 2013 with OS X Maverics, when I tried to execute IDLE, the window appears and disappear instantly. When I tried to do the same from the ...
0
votes
0answers
19 views
CSV Writer inserting extra lines
I'm having the same issue reported here, but the solutions aren't really related to the extra lines, they're pointing out that the original file is being opened incorrectly.
Python 3.3 CSV.Writer ...
0
votes
2answers
29 views
lambda function with re.sub in Python 3 [on hold]
-1- What does the below code?
part = re.sub('(.{3}).', lambda match: match.group(1), mass, flags=re.DOTALL)
-2- What is Python 3 equivalent of the above code snippet?
Note, in Python 2 the "mas" ...
0
votes
1answer
18 views
How can i get the GUI to accept my input
I also need help getting my variable named "guess" to work.I made it a paramater also in hopes of getting it to work.I have to make a guess my number program with a gui interface the code i have so ...
0
votes
3answers
25 views
Write string and date to text file in Python 3
Trying to figure out how to out a guessing game score plus the date & time to a text file with a new line each time, keeping the old text.
This is what I've got so far;
print('You scored %s.' % ...
-1
votes
1answer
51 views
list append not working correctly
I have code that is supposed to fill in IP address ranges so that none overlap. I have had a previous version of this that works great but I changed it automate all the passes and be less wasteful and ...
0
votes
1answer
8 views
Crcmod python3 polynomial error
I need to use a crc checksum in a python3 program, but my knowledge of crc is virtually non-existent.
Here is the test code I wrote
import crcmod
crc_func = crcmod.mkCrcFun(0x1d, initCrc=0x07, ...
0
votes
0answers
15 views
How to get information out of the multenterbox function Easygui
I am creating a Contact book program for windows 7 with Python 3.3, and I'm trying to use the Easygui multenterbox() function to have the user enter all the contact information at once. I want to ...
1
vote
1answer
22 views
Convert string to compiled regex matching the exact string
Is there a simple way to transform an exact string matching to a re.compile object ? For example, I would like to mix exact string and regexes.
0
votes
4answers
66 views
Python generating random numbers
This is my code:
import random
minimum=int(input("Enter minimal value: "))
maximum=int(input("Enter maximum value: "))
howMany = int(input("How many numbers do you want to generate?"))
sum=0
n=1
...
1
vote
4answers
61 views
Checking if number is within more or less range in Python
I'm new to Python as part of an exercise I'm making a simple number guessing game. I've gotten the basics covered, but I'm trying to implement a manner which tells the user if their guess is close or ...
-1
votes
1answer
28 views
Invalid syntaxs and defining [on hold]
I am currently using the New Boston python tutorial and have got up to the bit where he describes defining.
Seeing that the tutorial is not using Python 3+, I think the error maybe because of the ...
1
vote
3answers
39 views
Call a function then reverse arguments of the same function and call again
I was wondering if this was possible in one function:
def test(x, y):
print(x, "+", y)
When I call test, I want to call test(1, 2) followed immediately by test(2, 1).
This is inside of a ...
1
vote
2answers
52 views
Condensing Repetitive Code in Python?
Ways to condense these?
col1 = [row1[0],row2[0],row3[0],row4[0],row5[0]]
col2 = [row1[1],row2[1],row3[1],row4[1],row5[1]]
col3 = [row1[2],row2[2],row3[2],row4[2],row5[2]]
col4 = ...
0
votes
1answer
41 views
syncdb command not working properlly
I am trying to run the existing project.I had restored my database and installed all the required dependencies.While running syncdb,i got the below errors.
[root@localhost ]# python manage.py syncdb
...
2
votes
2answers
37 views
Python 3.2 - Symétric AES Crypto in CBC mode - advices requested
My goal is to setup simple encryption with python 3.x, so I searched the web this weekend to get informations about RSA / AES and so on ... Actually, things that may look like a possibility to encrypt ...
2
votes
1answer
34 views
how to tranfrom python3 program into exe file totally?
I have heard py2exe,but it doesn't support python3 now.So I found cxfreeze,but there is an problem that the extension lib are in a zip file,but one extension must use a txt file.The extension would ...
1
vote
3answers
51 views
Using the same name for variables which are in different functions?
I've been searching a while for my question but haven't found anything of use. My question is rather easy and straightforward.
Is it preferable or perhaps "pythonic" to use the same name for a ...
1
vote
1answer
46 views
Dictionary Comprehension in Python 3
I found the following stack overflow post about dict comprehensions in Python2.7 and Python 3+: Python: create a dictionary with list comprehension stating that I can apply dictionary comprehensions ...
0
votes
4answers
28 views
difference between sys.stdout.write and print when printing variables
I would like to learn the difference between sys.stdout.write and print methods(or functions? Should I call them function or method?)
For example, the code below will print 11
a = str(1)
...
0
votes
3answers
34 views
python _mysql_exceptions.ProgrammingError: (2014, “Commands out of sync; you can't run this command now”)
I am trying to run the existing project in centos machine.I installed packages from requirements.txt and it installed sucessfully.But while run "python manage.py runserver" i am getting the following ...
0
votes
1answer
33 views
Python 3 Tkinter - Disabling buttons out of order code
Currently I am attempting to disable certain buttons in my UI when a certain condition is met. The only problem is I can only change the state of a button after it is created.
I made a Disabler class ...
0
votes
4answers
52 views
How many letter were changed in string
Hello I am fairly new at programming,
I would like to know is there a function or a method that allows us to find out how many letters have been changed in a string..
example:
input:
"Cold"
...
3
votes
2answers
26 views
How to create multiple sprites which are similar?
Let me show you the code which may help make this question make more sense.
import pygame, classes, random
pygame.init()
screen = pygame.display.set_mode((640, 480))
def game():
...
0
votes
2answers
38 views
Create a tuple from an input in Python
Here is my example:
>>> a=input ('some text : ') # value entered is 1,1
>>> print (a)
1,1
I want as a result a tuple (1, 1)
How can I do this?
-2
votes
3answers
78 views
Getting int from string in list
I still have some issues concerning editing some values in a list.
My list consist of the following:
listInfo = [["Appel",3,"Pitvrucht"], ["Peer",6,"Pitvrucht"], ["Banaan",3,"Exotisch]=, ...
0
votes
1answer
37 views
Getting this to put on file and get rid of error code
This is supposed to put this information onto a new file but i get an error saying 'tuple' object has no object 'write' so I need some help to figure out what is wrong in my code.
def ...
0
votes
1answer
22 views
Scroll to the contrary
Here is my code:
n=int(input())
from math import *
while n!=0:
print (n,"\t",log10(n))
n=n-1
Its output is:
10 1.0
9 0.9542425094393249
8 0.9030899869919435
7 ...
-3
votes
2answers
39 views
How to loop in the opposite order?
I am a Beginner Programmer
Here is my code:
n=int(input())
from math import*
for i in range(n):
print(n,"\t",log10(n))
i=i+1
n=n-1
Its output is:
10 1.0
9 0.9542425094393249
8 ...
-1
votes
6answers
63 views
how to know if even number of elements or odd in a list
how to find if there is even number of elements or odd number of elements in a arbitrary list.
I tried list.index() to get all the indexes... but I still dont know how I can tell the program that ...
0
votes
3answers
53 views
How to have shared variables between modules in Python
I started lately to use Python instead of Matlab and I have a question to which the answer might be obvious but I can't figure it out yet.
I have the following module in python called ...
0
votes
0answers
14 views
can Django-mptt work in python 3.3?
i see its intreduction say
Python 2.6+ (with experimental support for python 3.2+)
and now my project will use python 3.3 + and django 1.6
any one know the django mptt can run well in python 3.3
...
0
votes
1answer
15 views
How to add a library in python urllib2
I am using python ver 3.3. I am trying to access the requests.get() method. But I am not able to access this because in my
import requests
It is showing module not found. How can I install this for ...
1
vote
0answers
15 views
How do I get string representation of PyObject in Python3?
I am debugging Python source code (CPython 3.4). I'm receiving a PyObject*. I would like to printf it.
For example (from Objects/floatobject.c of Python 3.4 source code):
PyObject *o_ndigits = NULL;
...
1
vote
2answers
49 views
Seprating : values from list and write into csv file
I have below piece of code . where i wanted to separate date:07/12/13 and write it into csv file.but i couldn't able to separate element from list, i have tested list component over the py scripted ...
1
vote
0answers
55 views
ImportError: cannot import name force_text
I have installed python 2.7 and django 1.4 in my centos machine and installed all dependencies for my existing project.When i run "python manage.py runserver" i am getting the following traceback in ...
0
votes
3answers
51 views
How to find duplicate values in dictionaries
How can we find and remove duplicate values along with their keys from a dictionary.
Example:
f = {1:4, 1:3, 4:4, 9:4, 5:7}
Output:
f = f = {1:3, 5:7}
As you can see all the keys with they ...
1
vote
3answers
69 views
Does Python have a way to repeat a given number of times without explicitly assigning a counter variable?
I occasionally find myself writing
for i in range(n):
stuff_that_does_not_involve_i
Is there some better way to do that; perhaps something along resembling
do n times:
whatever
?
(Note that ...
1
vote
3answers
41 views
how to find value using key in dictionary
Hello I am trying to find the values in a dictionary using they keys which is a 2 element tuple.
For example any basic dictionary would look like this:
dict = {'dd':1, 'qq':2, 'rr':3}
So if I ...
3
votes
2answers
55 views
how can you hide letters in a word with an asterisk?
i am currently working on a hang man project. i am having problems with hiding characters in word with asterisk. so for "word" would be ****. Then when the player make a guess and its correct the ...
0
votes
1answer
29 views
Delete whitespace characters in quoted columns in tab-separated file?
I had a similar text file and got great help to solve it, but I have to realize that I'm too new to programming in general and regex in particular to modify the great Python script below written by ...
2
votes
4answers
77 views
Sum up all the integers in range()
I need to write a program that sums up all the integers which can be divided by 3 in the range of 100 to 2000. I'm not even sure where to start, so far I've got this tiny piece of code written which ...
2
votes
1answer
42 views
python 3.0 “with” syntax error?
i have a syntax error with the with statement. i cant figure it out. i am using python 3 and every time i use the with statement it just wont have it. i am trying to make a reader for a txt file and i ...
1
vote
0answers
28 views
How this dictionary works in simpleubjson encode in python?
I wounder how this works, I wrote a simple binary exporter similar format json to simpleubjson not same, but my codes is slower while simipleubjson is faster and I noticed simplubjson use a dictionary ...
0
votes
3answers
56 views
How do you combine 2 similar if statements to shorten your python programming code?
I am working on a python project and need to combine 2 similar if statements to shorten the length of my code.
Here is the selection of code I need to combine:
if value1 < 14:
value1 = 10
...
0
votes
2answers
48 views
Python: alphabet count
I need someone to help me with the explaination for the below code.
After looking at the solution, it took me some time to figure out that the number actually represents the humber of times the ...
4
votes
2answers
2k views
PyCrypto install error on Windows
I am trying to install PyCrypto 2.6 Library on my computer. But I keep getting the following error
D:\Software\Python\package\pycrypto-2.6>python setup.py build
running build
running build_py
...
2
votes
2answers
666 views
sys.argv as bytes in Python 3k
As Python 3k introduces strict distinction between strings and bytes, command line arguments in the array sys.argv are presented as strings. Sometimes it is necessary to treat the arguments as bytes, ...
21
votes
6answers
21k views
How to install pip with Python 3?
I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2.
How can I install pip with Python 3?