sys

Create a username using Python

Create a username using Python Question: I’m just learning Python and have to create a program that has a function that takes as arguments a first and last name and creates a username. The username will be the first letter of the first name in lowercase, the last 7 of the last name in lowercase, …

Total answers: 3

Python 3.6 sleep() different sleep times within same string depending on character

Python 3.6 sleep() different sleep times within same string depending on character Question: In python 3.6, I’m trying to get a string to print with a delay between characters and a longer delay for punctuation at the end of sentences to pseudo-simulate spoken English. Here is my code. My problem is that I get the …

Total answers: 3

PYGAME: sysFont ERROR

PYGAME: sysFont ERROR Question: i am following allong with a pygame-tutorial but i have, even if i use the source code, this error Traceback (most recent call last): File “C:UsersMichaëlDocumentspythonfileText-5.py”, line 29, in <module> font = pygame.font.SysFont(None, 25) File “C:UsersMichaëlAppDataLocalProgramsPythonPython36-32libsite-packagespygamesysfont.py”, line 320, in SysFont return constructor(fontname, size, set_bold, set_italic) File “C:UsersMichaëlAppDataLocalProgramsPythonPython36-32libsite-packagespygamesysfont.py”, line 243, in font_constructor …

Total answers: 2

Does `print()` delay in some consoles where `stdout.flush` doesn't?

Does `print()` delay in some consoles where `stdout.flush` doesn't? Question: I’m working on an open source python library that uses a verbose_print command to log outputs in the console. Currently it looks like this: def sys_write_flush(s): """ Writes and flushes without delay a text in the console """ sys.stdout.write(s) sys.stdout.flush() def verbose_print(verbose, s): """ Only …

Total answers: 1

Python program to execute any other Python program as argument?

Python program to execute any other Python program as argument? Question: I am trying to write a Python program to to execute another Python program using subprocess. What wrong in this program, and how can I take the other Python program as an argument? import sys import subprocess def dorun(args): subprocess.Popen([sys.executable, ‘%r’] % args) dorun() …

Total answers: 1

The fastest way to generate string of zeros

The fastest way to generate string of zeros Question: I need to generate some string of zeros for example: import sys MB = 1024 * 1024 cache = ” while sys.getsizeof(cache) <= 10 * MB: cache = cache + “0” and save it to the file, but I have the impression that this method is …

Total answers: 2

Get parent of current directory from Python script

Get parent of current directory from Python script Question: I want to get the parent of current directory from Python script. For example I launch the script from /home/kristina/desire-directory/scripts the desire path in this case is /home/kristina/desire-directory I know sys.path[0] from sys. But I don’t want to parse sys.path[0] resulting string. Is there any another …

Total answers: 10

What does sys.stdin read?

What does sys.stdin read? Question: I get how to open files, and then use Python’s pre built in functions with them. But how does sys.stdin work? for something in sys.stdin: some stuff here lines = sys.stdin.readlines() What’s the difference between the above two different uses on sys.stdin? Where is it reading the information from? Is …

Total answers: 6