Search Results
|
Post |
Author |
Forum |
Replies |
Views |
Posted
[asc]
|
|
|
Thread: iterating through a number of files
Post: iterating through a path
My assignment is to find the number of times a given name shows up in per text file in the path of 100+ files (I should have a different number for each text file, not just 1 number for the total in t... |
|
gonzo620 |
Homework |
6 |
3,300 |
Nov-26-2018, 09:41 PM |
|
|
Thread: iterating through a number of files
Post: RE: iterating through a number of files
(Nov-21-2018, 11:21 PM)Gribouillis Wrote: An alternative with generator functions
def iterfiles(path):
return (entry for entry if path.iterdir() if entry.is_file())
there a syntax error in this ... |
|
gonzo620 |
Homework |
6 |
3,300 |
Nov-26-2018, 09:30 PM |
|
|
Thread: iterating through a number of files
Post: iterating through a number of files
My current code will list the total number of occurrences of the user input within all the files in the path. How can I edit the code to show me the occurrence of the input for each txt file?
import... |
|
gonzo620 |
Homework |
6 |
3,300 |
Nov-21-2018, 09:56 PM |
|
|
Thread: iterating through all files from a folder
Post: RE: iterating through all files from a folder
(Nov-06-2018, 01:29 AM)nilamo Wrote: (Nov-06-2018, 12:50 AM)gonzo620 Wrote: from my current codeidk, what's your current code look like?
import pathlib
name = input('What name are you interested ... |
|
gonzo620 |
Homework |
10 |
8,236 |
Nov-06-2018, 01:48 AM |
|
|
Thread: iterating through all files from a folder
Post: RE: iterating through all files from a folder
Sorry for all the questions. For another assignment I now need to get the number of occurrences a given name has per file. The current program finds the total occurrence in all the files together. How... |
|
gonzo620 |
Homework |
10 |
8,236 |
Nov-06-2018, 12:50 AM |
|
|
Thread: iterating through all files from a folder
Post: RE: iterating through all files from a folder
(Oct-30-2018, 05:57 PM)gonzo620 Wrote: this program is printing a 1 for every occurrence of 'name'. What I want is to print the total number of occurrences 'name' has throughout all the files. What ... |
|
gonzo620 |
Homework |
10 |
8,236 |
Oct-30-2018, 07:01 PM |
|
|
Thread: iterating through all files from a folder
Post: RE: iterating through all files from a folder
You've been a huge help! I just have one last question.
import pathlib
name = input('Enter a name: ')
path = pathlib.Path("./Names")
for entry in path.iterdir():
if entry.is_file():
wit... |
|
gonzo620 |
Homework |
10 |
8,236 |
Oct-30-2018, 05:57 PM |
|
|
Thread: iterating through all files from a folder
Post: RE: iterating through all files from a folder
(Oct-29-2018, 09:09 PM)nilamo Wrote: https://docs.python.org/3/library/pathlib.html
Pathlib is a good place to start. Something likeimport pathlib
path = pathlib.Path('./data_folder')
for entry i... |
|
gonzo620 |
Homework |
10 |
8,236 |
Oct-30-2018, 12:18 AM |
|
|
Thread: iterating through all files from a folder
Post: iterating through all files from a folder
I need to write a Python program that iterates through all the data files in a folder and calculates the total number of occurrences of a given name. For example, the user would input a name, Bob, and... |
|
gonzo620 |
Homework |
10 |
8,236 |
Oct-29-2018, 08:58 PM |
|
|
Thread: organizing by distance
Post: RE: organizing by distance
(Oct-16-2018, 12:28 AM)stullis Wrote: First, there are a couple things to adjust before getting to the problem at hand. All the lines from 53 down should not be in the for loop started on line 15. B... |
|
gonzo620 |
General Coding Help |
7 |
3,943 |
Oct-16-2018, 01:22 AM |
|
|
Thread: Help with list sorting
Post: Help with list sorting
Can someone help with my assignment. I have most of the code written theres just a few errors I need help with.
the text file and assignment: https://transfernow.net/49ffh2n6pjez
The code:
with open... |
|
gonzo620 |
Homework |
1 |
3,144 |
Oct-15-2018, 08:55 PM |
|
|
Thread: organizing by distance
Post: RE: organizing by distance
this is the text file https://transfernow.net/91bu72e2wb1l
My current code:
with open('cities.txt','r', encoding = 'cp1252') as fin: # opens file with read permission
import math
season... |
|
gonzo620 |
General Coding Help |
7 |
3,943 |
Oct-15-2018, 04:30 PM |
|
|
Thread: organizing by distance
Post: RE: organizing by distance
(Oct-11-2018, 01:55 AM)stullis Wrote: If you want to sort them by distance (closest first), you'll need to create a list of cities and use the list.sort() method. You could append the distance to ea... |
|
gonzo620 |
General Coding Help |
7 |
3,943 |
Oct-11-2018, 03:55 AM |
|
|
Thread: organizing by distance
Post: organizing by distance
This is my code. Depending on the season and climate chosen I need to print the 5 closest cities from to coordinates 37°22'N and 107°25'W. I don't know where I would go from here. How do I find the cl... |
|
gonzo620 |
General Coding Help |
7 |
3,943 |
Oct-10-2018, 11:27 PM |
|
|
Thread: Files handling and lists
Post: RE: files, lists, and if statements
(Oct-09-2018, 12:52 AM)ichabod801 Wrote: Okay, but fout just creates a file without the header. It doesn't change data. If you want to skip the first row, just loop over data[1:].
You might want to... |
|
gonzo620 |
General Coding Help |
12 |
5,455 |
Oct-09-2018, 01:29 AM |
|
|
Thread: Files handling and lists
Post: RE: files, lists, and if statements
(Oct-08-2018, 10:08 PM)ichabod801 Wrote: Once you read a file it's done. You read fin on line 2, putting it into data. So when you try to read it again on line 11, there's nothing left, and your loo... |
|
gonzo620 |
General Coding Help |
12 |
5,455 |
Oct-08-2018, 11:06 PM |
|
|
Thread: Files handling and lists
Post: files, lists, and if statements
I am trying to read a text file and add each row into an appropriate list, but my lists return empty
with open('cities.txt','r', encoding = 'cp1252') as fin: # opens file with read permission
dat... |
|
gonzo620 |
General Coding Help |
12 |
5,455 |
Oct-08-2018, 10:01 PM |
|
|
Thread: Files handling and lists
Post: files handling, if statements, and lists
I am trying to read a text file and add each row into an appropriate list, but my lists return empty
with open('cities.txt','r', encoding = 'cp1252') as fin: # opens file with read permission
data... |
|
gonzo620 |
General Coding Help |
12 |
5,455 |
Oct-08-2018, 05:57 AM |
|
|
Thread: Files handling and lists
Post: RE: Files handling and lists
gonzo620 Wrote:i.e: can I print the element in the 3rd column directly(I know you can print lines but does it work with columns?)You don't have any column only lines,have to split the lines.
Then line... |
|
gonzo620 |
General Coding Help |
12 |
5,455 |
Oct-05-2018, 03:21 PM |
|
|
Thread: Files handling and lists
Post: RE: Files handling and lists
Also, is there an easier way to do this other than lists?
i.e: can I print the element in the 3rd column directly(I know you can print lines but does it work with columns?) |
|
gonzo620 |
General Coding Help |
12 |
5,455 |
Oct-04-2018, 07:57 PM |