Tagged Questions
0
votes
0answers
19 views
ImportError: No module named 'PIL' in python 3.4
I have such code in the beginning of a file:
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
And it throws the error:
python3 main.pyTraceback (most recent call last):
...
0
votes
1answer
26 views
Can i access python function inside in same function?
Can i access python function inside in same function or sub function of main function?
def main_function():
def sub_function():
main_function() # i need to call main function.can i or ...
0
votes
2answers
20 views
How to encode text to base64 in python
I am trying to encode a text string to base64.
i tried doing this :
name = "your name"
print('encoding %s in base64 yields = %s\n'%(name,name.encode('base64','strict')))
But this gives me the ...
0
votes
1answer
5 views
Python 3 and sqlachemy model's properties
I have two declarative sqlalchemy models.
class Users(Base):
__tablename__ = 'Users'
ID = Column(INTEGER, primary_key=True)
_Activities = relationship('Activities', lazy='subquery')
...
1
vote
1answer
32 views
How to set which version of python sublime text uses
I have been teaching myself python and started out using python 2.7.5 and Sublime Text 2. I recently enrolled in a class and they are using python 3.4. I downloaded and installed python 3.4 onto my ...
3
votes
1answer
41 views
Trying to rearrange two dimensional list into a different two dimensional list
Given an input of something like:
"Date 3" "Location A" "some data"
"Date 3" "Location B" "some data"
"Date 3" "Location C" "some data"
"Date 2" "Location A" "some data"
"Date 2" "Location B" ...
-2
votes
0answers
14 views
Write RGB value to pixel on an image
So I have been googling for a good library to read and write RGB values of pixels specified by coordinates. I found a couple of them like: Python Image Library and PyPNG. What I would like to know is ...
3
votes
1answer
43 views
Python “maximum recursion depth exceeded in comparison” with variable arguments. Works fine with lists, howerver
I have the following function:
def lst(*l):
if l==():return None
else: return cons(l[0],lst(l[1:]))
When I run it, I get "maximum recursion depth exceeded in comparison". Curiously, when I add ...
0
votes
2answers
67 views
How can i speed up this python code?
So I recently coded this as a little challenge to see how quick I could do it. Now since its working an such I want to speed it up. It finds all the proper devisors of a number, the highest proper ...
-1
votes
2answers
36 views
how can i display my sentence in python 3.3?
how can i display a sentence in the my program ..
if i have this sentence: " i play football" and i want to replace a letter "o" for example with "e"....
i do that with the following code and that ...
-7
votes
0answers
45 views
Array to linked list python [on hold]
I have a program that gets an array from the user. Here it is:
def main():
array = eval(input("Give me an array of numbers: "))
How do I convert this array into a linked list?
0
votes
0answers
24 views
N-ary tree in python
I want to create a N-ary tree in which each node will contain a key(name) and a value.
1 root then N children with two fields = name and associate value
and again each children have N-children with 2 ...
0
votes
2answers
47 views
Rename class object name within class itself
class User:
def __init__(self, username):
self.name = username
def _chusername(self, new_name):
old = self.name
self.name=new_name
foo = User('foo')
...
1
vote
1answer
17 views
Python: tkinter, adding entry to listbox doesn't response
For some reason, it doesn't add the element to the listbox. I guess it's because of the program order, but i'm not sure how should I properly put the code in the right order
Here is the code:
from ...
1
vote
1answer
26 views
Update 2D List with tuple in Python
My List is like this:
[('void ', 'treeInit', 'tSymbolTree *T'),('tTreeItemPtr ', 'nodeInsert', 'tTreeItemPtr *T')]
and if I call:
>>>list[0][0]
void
and now it's the problem I using ...
1
vote
2answers
42 views
how to remove characters from printed output in python
I am trying to remove extra characters printed out in my print statement from another print statement.
Here is what my code looks like:
print(addedlist) #addedlist = [9,5,1989,1,2,3,4,5,6,7,8,9]
...
0
votes
1answer
28 views
How to for loop in print statement
I am trying to format my output to print with 7 whitespaces at the beginning.
for i in range(1,17):
print(i, end=' ')
How could I include that in a formatted statement?
For example:
...
1
vote
2answers
20 views
Only Wanting Unique Words in my output file
I am trying to write some code that takes an input file which is a paragraph of text(this paragraph has duplicates of certain words), I then want to write this text to an output file, however I do not ...
4
votes
1answer
42 views
Python: How to remove a list containing Nones from a list of lists?
I have something like this:
myList = [[1, None, None, None, None],[2, None, None, None, None],[3, 4, None, None, None]]
And if any of the lists in the list have 4 Nones, I want to remove them so ...
0
votes
1answer
34 views
Issues with classes in Python 3: class doesn't recognize variable that was declared within it
I am creating a calculator in Python 3 in which you can type a full problem such as:
3 + 2
or
5 * 2
And I want it to be able to calculate just from that info.
Here is the code I already have:
# ...
0
votes
1answer
17 views
In python is possible to call main method of other class from
Here is my programs
1.post-commit.py
2.commit-comments.py
I need to call main method of commit-comments from post-commit.py with 5 arguements
Is that possible if so how can we do that
Thanks in ...
0
votes
1answer
17 views
How do I select items in MenuBar (PyQt/Python)
I have created the menu bar shown below as part of a QMainWindow Class and i wanted to run another class or def when i click on 'Save as...' in the Menubar. How could i edit the code below to allow me ...
0
votes
3answers
35 views
Think Python Chapter 10 Exercise 6 Stuck
Exercise:
Write a function called is_sorted that takes a list as a parameter and returns True if the list is sorted in ascending order and False otherwise. You can assume (as a precondition) that ...
0
votes
1answer
7 views
How do I remove the selected row/item from QListWidget?? (Python/PyQt)
I wanted to know how i could remove the current selected row/item in a QListWidget??
I used the code below with no luck! Although it returns no error, nothing happens? :
...
0
votes
3answers
39 views
Python: Looking for more efficient method of sorting list into sublists accounting for missing input
I'm still somewhat new to Python 3, and while I have something that works, I think it could be a lot more efficient and readable.
For example, if I have the input:
A1, B1, C1, A2, B2, A3, C3, C4
...
-1
votes
1answer
26 views
Python: Looping Through Multiple lists and Appending to list
I have 2 lists and using a range function i need to go through the list and print out a list of 10 tuples.
list_1=[3,43,34,34,32,43,54,45,45]
list_2=[3,43,34,34,2,34,23,23,43]
for indenti in ...
0
votes
2answers
43 views
Finding a common char between two strings recursively
Im trying to write a recursive code that recieves 2 strings and returns True is they have a common char or False if the dont.
I first wrote an iterative code cause I thaught it may help.
The problem ...
-1
votes
0answers
50 views
Python: Appending multiple values to a list [on hold]
Lets say I have a list:
listA=[0,1,2,3,4,5,6,7,8,9]
listB=[43,54,65,76,7,87,98]
listc=[45,656,767,878,989]
counter=0
myList=[]
for a in listA:
for b in listB:
for c in listC:
...
0
votes
0answers
18 views
How in Py3k do I prevent indigestion about non-ASCII characters in filenames?
I am working with a Python script that walks the filesystem and on later string-y operations, seems to force ASCII conversion. I would like the script to work in a straightforward way with filenames ...
0
votes
3answers
28 views
First index appearance in a string recursive
Im trying to write a recursive function that gets as an input a string and a char. the function return the first index appearance of the char in the string. If the char doesnt appear it returns None.
...
1
vote
3answers
25 views
Python - regex, blank element at the end of the list?
I have a code
print(re.split(r"[\s\?\!\,\;]+", "Holy moly, feferoni!"))
which results
['Holy', 'moly', 'feferoni', '']
How can I get rid of this last blank element, what caused it?
If this is a ...
-6
votes
0answers
40 views
Code works fine on Python 2.7 but incompatible with python 3.2? [on hold]
I have wrote a small text encryption code in Python 2.7. I tried to run it on a 3.2 machine. But it shows error. I don't know what part of my code is incompatible with the latest version.Here is my ...
-7
votes
1answer
78 views
How to do maths in python [on hold]
Okay, so I have two variables which are integers. I would like to find the average of these please, but I'm not sure how to through code.
Here is the code so far:
number = mod2+mod1
...
2
votes
3answers
58 views
How do I find out what key failed in Python KeyError?
If I catch a KeyError, how can I tell what lookup failed?
def POIJSON2DOM (location_node, POI_JSON):
try:
man_JSON = POI_JSON["FastestMan"]
woman_JSON = POI_JSON["FastestWoman"]
except ...
-1
votes
1answer
30 views
Issue with saving into a Txt in python 3.3.2
I have created a piece of code to save some data generated by my code into a txt file on my pc, however when ever i run the program i receive this error,
Traceback (most recent call last):
File ...
0
votes
1answer
41 views
Breaking out of infinite loop
My code is not allowing me to break out of the infinite loop, and therefore exit the program. Here is my code:
while True:
print("\n1. Surname\n2. D.O.B\n3. Quit")
try:
...
-2
votes
3answers
45 views
Python: Converting scores into a grade - parameters [duplicate]
Okay, so for my homework I need to write a function that will convert a score into a grade...
name = input("Hello, what is your name?\n")
print("Welcome", name)
mod1 = int(input("Please enter your ...
-3
votes
0answers
29 views
File saving error in python [on hold]
I am having issues with saving my data i get with my code, im not sure how to finish it and i have a deadline approaching, so if someone could point out where i went wrong and assist me in fixing it ...
-11
votes
0answers
56 views
creating classes and functions using python [on hold]
You are to write three program/module as described below:
The first is a class called Song which defines a simple object type representing a song.
The second class called SongOrgainser defines ...
1
vote
0answers
15 views
_socket module import error on fresh python 3.3.5 install
I installed python 3.35 and I'm getting this error:
Traceback (most recent call last):
File "C:/Users/Augusto/PycharmProjects/Plot/Database.py", line 48, in <module>
import socket
File ...
1
vote
1answer
46 views
Passing Parameters as Coordinates
I have a text file with coordinates on it like the following example. My aim was to load the file and create it into coordinates to plug into turtle to draw something, but when I try the whole thing ...
0
votes
2answers
23 views
Validation loop error
I am trying to validate my python script:
def DOBSearch():
loop = True
while loop == True:
try:
DOBsrch = int(input("Please enter the birth month in a two digit format ...
1
vote
2answers
26 views
Why do we sometimes need to import module1.module2 but sometimes not?
Why do we need to import module1.module2 if we can just import module1?
Example:
Why do we need import tkinter.messagebox and do tkinter.messagebox.askyesno(“blah text”) when we also can do import os ...
0
votes
1answer
12 views
How do I properly construct an UPDATE statement that references an attached database table?
this question pertains to Python3's sqlite3 module (DB-API 2.0 interface for SQLite databases).
I am trying to update a sqlite3 database column where there are equivalent values in an attached ...
7
votes
1answer
68 views
Lazily transpose a list in Python
So, I have an iterable of 3-tuples, generated lazily. I'm trying to figure out how to turn this into 3 iterables, consisting of the first, second, and third elements of the tuples, respectively. ...
0
votes
1answer
32 views
Python counting the unique occurences of a string in a file
I’m trying to count the unique IP addresses in a Apache log-file using python 3.3.1
The thing is I don’t think that it is counting everything correctly.
Here is my code:
import argparse
import os
...
0
votes
2answers
40 views
Python Pygame Shape Rotation Issue
I'm fairly new to Pygame and i'm trying it out making a simple little game, i'm currently having issues rotation a rectangle. The shape in it's self rotates however for some reason when the shape ...
0
votes
1answer
31 views
Thread condition variables: un-acquired lock
I have this example in Python which demonstrates the use of condition variables.
import logging
import threading
import time
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s ...
2
votes
1answer
18 views
get mutable default arguments of func
How do I get the mutable default arguments tuple in Python 3?
def foo(x=[]):
pass
Failed Attempt:
foo.func_defaults
Error:
AttributeError: 'function' object has no attribute 'func_defaults'
...
0
votes
2answers
48 views
Obtaining *args and **kwargs from passed func
In the below code, how would I obtain *args and **kwargs in function f without the need for the wrapper function?
def f(func):
def wrapper(*args, **kwargs):
print(args)
...