python-3.5

closing all windows in python tkinter

closing all windows in python tkinter Question: I am working with tkinter library in python. I have a main window which has several buttons and when clicked those buttons a new window will popup which also has a button called cancel. I want to make that cancel button to all the windows. I tried the …

Total answers: 2

"Asyncio Event Loop is Closed" when getting loop

"Asyncio Event Loop is Closed" when getting loop Question: When trying to run the asyncio hello world code example given in the docs: import asyncio async def hello_world(): print(“Hello World!”) loop = asyncio.get_event_loop() # Blocking call which returns when the hello_world() coroutine is done loop.run_until_complete(hello_world()) loop.close() I get the error: RuntimeError: Event loop is closed …

Total answers: 3

Should a class convert types of the parameters at init time? If so, how?

Should a class convert types of the parameters at init time? If so, how? Question: I’ve defined a class with 5 instance variables class PassPredictData: def __init__(self, rating, name, lat, long, elev): self.rating = rating # rest of init code I want to ensure: rating is an int name is a str lat, long, elev …

Total answers: 7

How to set Python3.5.2 as default Python version on CentOS?

How to set Python3.5.2 as default Python version on CentOS? Question: Is there a way to set the Python 3.5.2 as the default Python version on CentOS 7? currently, I have Python 2.7 installed as default and Python 3.5.2 installed separately. I used the following commands mv /usr/bin/python /usr/bin/python-old sudo ln -fs /usr/bin/python3 /usr/bin/python but …

Total answers: 6

Duck typing with python 3.5 style type-annotations

Duck typing with python 3.5 style type-annotations Question: Supposing I have a function with a signature like: def foo(self, name:str, stream): pass I want to add an annotation to the "stream" argument so which means "you can have any object x as long as x.readline()->str". So that means I could use any python file object …

Total answers: 3

CSV read columns corresponding to other columns values

CSV read columns corresponding to other columns values Question: I need to parse a csv file. Input: file + name: Index | writer | year | words 0 | Philip | 1994 | this is first row 1 | Heinz | 2000 | python is wonderful (new line) second line 2 | Thomas | 1993 …

Total answers: 4

Django: python manage.py migrate does nothing at all

Django: python manage.py migrate does nothing at all Question: I just started learning django, and as i try to apply my migrations the first problem occurs. I start the server up, type python manage.py migrate and nothing happens. No error, no crash, just no response. Performing system checks… System check identified no issues (0 silenced). …

Total answers: 8

ImportError: No module named 'django.core.urlresolvers'

ImportError: No module named 'django.core.urlresolvers' Question: I am working on Django project where I need to create a form for inputs. I tried to import reverse from django.core.urlresolvers. I got an error: line 2, in from django.core.urlresolvers import reverse ImportError: No module named ‘django.core.urlresolvers’ I am using Python 3.5.2, Django 2.0 and MySQL. Asked By: …

Total answers: 12

Why do external functions cause the PyQt5 window to freeze?

Why do external functions cause the PyQt5 window to freeze? Question: Here is some sample code that breaks: import sys import time from PyQt5.QtWidgets import (QApplication, QDialog, QProgressBar) class Actions(QDialog): def __init__(self): super().__init__() self.initUI() def initUI(self): self.progress = QProgressBar(self) self.progress.setGeometry(0, 0, 300, 25) self.show() self.count = 0 while self.count < 100: self.count += 1 time.sleep(1) …

Total answers: 2

Optional[Type[Foo]] raises TypeError in Python 3.5.2

Optional[Type[Foo]] raises TypeError in Python 3.5.2 Question: This code: #!/usr/bin/env python from typing import Optional, Type class Foo(object): pass class Bar(Foo): pass def test_me() -> Optional[Type[Foo]]: print(“Hi there!”) return Bar if __name__ == “__main__”: test_me() will raise TypeError on 3.5.2: Traceback (most recent call last): File “./test.py”, line 11, in <module> def test_me() -> Optional[Type[Foo]]: …

Total answers: 3