756 Answered Questions for the topic Python
Python Newline
05/11/19
How to print without newline or space?
The question is in the title.I'd like to do it in [tag:Python]. What I'd like to do in this example in [tag:C]:<!-- language: lang-c --> #include <stdio.h> int main() { ...
more
05/10/19
What does if __name__ == "__main__": do?
What does the `if __name__ == "__main__":` do? # Threading example import time, thread def myfunction(string, sleeptime, lock, *args): while True: lock.acquire() ...
more
05/10/19
Meaning of @classmethod and @staticmethod for beginner?
Could someone explain to me the meaning of `@classmethod` and `@staticmethod` in python? I need to know the difference and the meaning. As far as I understand, `@classmethod` tells a class that...
more
Python
05/10/19
How to read a text file into a string variable and strip newlines?
I use the following code segment to read a file in python: with open ("data.txt", "r") as myfile: data=myfile.readlines()Input file is:<!-- language: lang-none --> ...
more
Python Mysql
05/09/19
How do I connect to a MySQL Database in Python?
How do I connect to a MySQL database using a python program?
05/09/19
How to prettyprint a JSON file?
I have a JSON file that is a mess that I want to prettyprint-- what's the easiest way to do this in python? I know PrettyPrint takes an "object", which I think can be a file, but I don't know how...
more
Python
05/09/19
I am not a US Citizen
Hello wyzant.com,I am not a US citizen. Can I teach on wyzant.com with you.RegardSajid U.Thanks
Python Environment Variables
05/08/19
How do I access environment variables from Python?
I set an environment variable that I want to access in my Python application. How do I get this value?
05/08/19
What is the use of "assert" in Python?
I have been reading some source code and in several places I have seen the usage of `assert`. What does it mean exactly? What is its usage?
05/08/19
Extracting extension from filename in Python?
Is there a function to extract the extension from a filename?
05/08/19
How to make a chain of function decorators?
How can I make two decorators in Python that would do the following? @makebold @makeitalic def say(): return "Hello"...which should return: "<i>Hello</i>"I'm not...
more
05/06/19
Why are default arguments evaluated at definition time in Python?
I had a very difficult time with understanding the root cause of a problem in an algorithm. Then, by simplifying the functions step by step I found out that evaluation of default arguments in...
more
How can I remove a trailing newline in Python?
What is the Python equivalent of Perl's `chomp` function, which removes the last character of a string if it is a newline?
05/05/19
How do I pass a variable by reference?
The Python documentation seems unclear about whether parameters are passed by reference or value, and the following code produces the unchanged value 'Original' class PassByReference: def...
more
Python Directory
05/05/19
How to find if directory exists in Python?
In the `os` module in Python, is there a way to find if a directory exists, something like: >>> os.direxists(os.path.join(os.getcwd()), 'new_folder')) # in pseudocode True/False
05/05/19
Using global variables in a function?
How can I create or use a global variable in a function?If I create a global variable in one function, how can I use that global variable in another function? Do I need to store the global variable...
more
05/04/19
Delete an element from a dictionary?
Is there a way to delete an item from a dictionary in Python?Additionally, how can I delete an item from a dictionary to return a copy (i.e., not modifying the original)?
05/04/19
open() in Python does not create a file if it doesn't exist?
What is the best way to open a file as read/write if it exists, or if it does not, then create it and open it as read/write? From what I read, `file = open('myfile.dat', 'rw')` should do this,...
more
Python Directory
05/03/19
Find current directory and file's directory?
In Python, what commands can I use to find:1. the current directory (where I was in the terminal when I ran the Python script), and2. where the file I am executing is?
Python Time
05/01/19
How do I get time of a Python program's execution?
I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.I've looked at the `timeit` module, but it seems it's only for small...
more
Select rows from a DataFrame based on values in a column in pandas?
How to select rows from a DataFrame based on values in some column in pandas? In SQL I would use: select * from table where colume_name = some_value. *I tried to look at pandas documentation...
more
Python Coding
04/30/19
I'm struggling in Python programming Class.
Class uses a book called Python for everyone.We meet with the teacher once a week for 2 hours.He usually only talks about the meaning of the chapter per week we go through.He gives HW and...
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.