Search Results
|
Post |
Author |
Forum |
Replies |
Views |
Posted
[asc]
|
|
|
Thread: Can read files in command prompt but not IDE
Post: Can read files in command prompt but not IDE
Why does writing files work in both the command prompt and PyCharm (IDE)...
a = open("workfile.txt", "w")
a.close()but reading them only works in the command prompt?
a = open("workfile.txt", "r")
... |
|
Exsul |
General Coding Help |
2 |
2,161 |
Sep-12-2019, 11:39 PM |
|
|
Thread: Is it possible to have an apostrophe inside { } in an f-string?
Post: RE: Is it possible to have an apostrophe inside { ...
(Sep-04-2019, 05:53 AM)perfringo Wrote: Just a gentle nudging: it's not good practice to obscure code with cryptic abbreviations.
If code base grows and other people read the code they will need a... |
|
Exsul |
General Coding Help |
6 |
9,588 |
Sep-05-2019, 12:37 AM |
|
|
Thread: Is it possible to have an apostrophe inside { } in an f-string?
Post: Is it possible to have an apostrophe inside { } in...
from random import choice as rc
string = f"never say you {rc(['can', 'can\'t'])} do something"
print(string)Output:File "C:/Users/Exsul/.PyCharmCE2019.2/config/scratches/scratch.py", line 3
stri... |
|
Exsul |
General Coding Help |
6 |
9,588 |
Sep-04-2019, 12:38 AM |
|
|
Thread: How to run a method on an argument in a formatted string
Post: RE: How to run a method on an argument in a format...
The answer was f-strings. return f"{self.subj.capitalize()} is happy." |
|
Exsul |
General Coding Help |
1 |
1,682 |
Aug-30-2019, 01:57 AM |
|
|
Thread: How to run a method on an argument in a formatted string
Post: How to run a method on an argument in a formatted ...
class Test:
def __init__(self):
self.name = "unnamed"
self.subj = "he"
self.poss = "his"
self.obj = "him"
self.reflex = "himself"
def quirks(self):
... |
|
Exsul |
General Coding Help |
1 |
1,682 |
Aug-30-2019, 12:52 AM |
|
|
Thread: weird result trying to remove numbers from a list
Post: RE: weird result trying to remove numbers from a l...
(Aug-26-2019, 07:52 AM)perfringo Wrote: There are too much unnecessary 'actions' in code.
You create new list, then create copy of that new list and then remove items from new list to get list wit... |
|
Exsul |
General Coding Help |
6 |
3,447 |
Aug-26-2019, 11:12 PM |
|
|
Thread: weird result trying to remove numbers from a list
Post: RE: weird result trying to remove numbers from a l...
The solution turned out to be fairly simple. From the official documentation:
Quote:If you need to modify the sequence you are iterating over while inside the loop (for example to duplicate selected... |
|
Exsul |
General Coding Help |
6 |
3,447 |
Aug-25-2019, 09:50 PM |
|
|
Thread: Is it possible to have an index (e.g., for a list) start at 1 instead of 0?
Post: RE: index question
(Aug-25-2019, 04:55 PM)perfringo Wrote: If you need this index/integer for iteration then one can use enumerate:
>>> for i, char in enumerate("abc", start=1):
... print(f"{i}. {char}")... |
|
Exsul |
News and Discussions |
4 |
2,837 |
Aug-25-2019, 07:50 PM |
|
|
Thread: Is it possible to have an index (e.g., for a list) start at 1 instead of 0?
Post: Is it possible to have an index (e.g., for a list)...
Is it possible to have an index (e.g., for a list) start at 1 instead of 0? |
|
Exsul |
News and Discussions |
4 |
2,837 |
Aug-25-2019, 04:36 PM |
|
|
Thread: effective means to flip boolean values?
Post: RE: effective means to flip boolean values?
(Aug-24-2019, 08:16 PM)perfringo Wrote: ndc85430 idea expressed in code:
>>> spam = True
>>> spam = not spam
>>> spam
False
>>> spam = not spam
>>> spam... |
|
Exsul |
General Coding Help |
3 |
4,367 |
Aug-25-2019, 03:58 PM |
|
|
Thread: effective means to flip boolean values?
Post: effective means to flip boolean values?
Is there a method or something to easily flip a Boolean value from False to True or vice versa? |
|
Exsul |
General Coding Help |
3 |
4,367 |
Aug-24-2019, 05:24 PM |
|
|
Thread: question about list comprehension
Post: question about list comprehension
I understand most of this:
>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]Output:[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]Equivalent to:
>>>
>>> co... |
|
Exsul |
General Coding Help |
3 |
2,316 |
Aug-22-2019, 03:19 AM |
|
|
Thread: weird result trying to remove numbers from a list
Post: weird result trying to remove numbers from a list
I'm trying to remove all the numbers from a list, but when I run the code, I get a strange result:
nums = [1, 2, 3, 4, 5]
words = ["I", "sing", "of", "arms", "and", "a", "man"]
both = nums + words
f... |
|
Exsul |
General Coding Help |
6 |
3,447 |
Aug-21-2019, 01:53 AM |
|
|
Thread: Passing an argument by reference
Post: RE: Passing an argument by reference
(Aug-10-2019, 03:49 PM)ichabod801 Wrote: The issue is whether the data type is mutable or immutable. Lists, sets, and dictionaries are mutable and are passed by reference. Tuples, strings, frozenset... |
|
Exsul |
General Coding Help |
12 |
4,709 |
Aug-20-2019, 01:31 AM |
|
|
Thread: ipython autocomplete broke indentation!
Post: RE: ipython autocomplete broke indentation!
I uninstalled iPython and cleaned the registry, but Tab still won't indent. |
|
Exsul |
General Coding Help |
6 |
4,527 |
Aug-20-2019, 01:29 AM |
|
|
Thread: [CRITICAL] [App ] Unable to get a Text provider, abort.
Post: RE: [CRITICAL] [App ] Unable to get a Text provide...
(Aug-16-2019, 04:36 PM)FreedomLegion Wrote: (Mar-30-2019, 05:54 PM)Exsul Wrote: OMG, I finally figured out what was wrong. Okay, even though Kivy was installed on my machine, and worked fine in t... |
|
Exsul |
GUI |
6 |
12,036 |
Aug-17-2019, 11:54 PM |
|
|
Thread: Passing an argument by reference
Post: Passing an argument by reference
Can you pass an argument by reference with data structures other than lists?
def try_to_change_list_contents(the_list):
print('got', the_list)
the_list.append('four')
print('changed to', ... |
|
Exsul |
General Coding Help |
12 |
4,709 |
Aug-10-2019, 03:12 PM |
|
|
Thread: How do you add the results together each time a function is called?
Post: RE: How do you add the results together each time ...
(Aug-09-2019, 12:48 AM)ichabod801 Wrote: (Aug-08-2019, 11:18 PM)Exsul Wrote: I don't understand how you're using num
For loops require a loop variable. You don't have to use that loop variable, an... |
|
Exsul |
General Coding Help |
10 |
5,132 |
Aug-09-2019, 01:24 AM |
|
|
Thread: How do you add the results together each time a function is called?
Post: RE: How do you add the results together each time ...
(Jul-31-2019, 01:42 AM)ichabod801 Wrote: First...
I don't understand how you're using num in
for num in range(1000):
counts[random.randint(1, 10)] += 1Num doesn't appear in the indented line.
... |
|
Exsul |
General Coding Help |
10 |
5,132 |
Aug-08-2019, 11:18 PM |
|
|
Thread: How do you add the results together each time a function is called?
Post: How do you add the results together each time a fu...
I made a program that randomly adds numbers between 1 and 10 to a list 1,000 times and then counts the number of times each number occurs in that list. The results are given as percentages.
import r... |
|
Exsul |
General Coding Help |
10 |
5,132 |
Jul-31-2019, 12:36 AM |