How to find specific files in a folder using python [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
There are different files in a folder, I would like to print files which are ended with IHDRT.exr. The correct answer for this job is as shown bellow:
#!/usr/bin/env python
import glob
for file in glob.glob("*.exr"):
if file.endswith('iHDRT.exr'):
print(file)

#!/usr/bin/env python
import glob
for file in glob.glob("*.exr"):
if file.endswith('iHDRT.exr'):
^^^^^^^^
print(file)
Its endswith and not endswidth

Use endswith, not endswidth! Error spelling

Related

Finding Current Enumeration: For file in files [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
Lets say I have:
for file in files
print(file)
But what I want is
for file in files
print(x)
where x is the iteration # of the current file as the program loops through all the files.
Use enumerate function
for ind, file in enumerate(files)
print(ind)

os.path.join to create filename in python with datetime not working in mac [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to generate a filename in python on mac to record data everyday so that the filename has date in filename. Please refer the command below.
oi_filename= os.path.join("markets","storage","oi_data_records_{0}.json".format(datetime.now().strftime(%d%m%Y)))
where markets is in Desktop and storage is in markets folder.
Error
File "<ipython-input-20-e3a1aee3f506>", line 21
oi_filename= os.path.join("markets","storage","oi_data_records_{0}.json".format(datetime.now().strftime(%d%m%y)))
^
SyntaxError: invalid syntax
The basic idea is everyday a file to be created with full date in name so that the rest of program can park the data in the respective file.
It's because you didn't put the %d%m%y in a string.
oi_filename= os.path.join("markets","storage","oi_data_records_{0}.json".format(datetime.now().strftime(%d%m%Y)))
should be:
oi_filename= os.path.join("markets","storage","oi_data_records_{0}.json".format(datetime.now().strftime("%d%m%Y")))
You are missing quotation marks for strftime(%d%m%y). It should be strftime('%d%m%y')

receiving lists using config parser [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am quite new to using config parser and have just discovered that my INI file hasn't been used as expected. as you can see below it has been seeing every letter as an individual list but I want the list to be separated by the commas.
config = ConfigParser()
config.read('Airline Gates/JST.ini')
print(len(config['Airports']['YMML']))
Output > 79
.ini
[Airport]
YMML=[E11,E12,E13,E14,E15,E16,E17,E18,E19,E20,G41,G42,G43,G44,G45,G46,G47,G50,G51,G52]
I am very sorry for a poor explanation I am awful at explaining things but I will be happy to give you any more information. thanks!
Go through This video https://www.youtube.com/watch?v=jBwfq6UMxkY for better understanding of ConfigParser. For your current problem you can format the string value from ini file as per your need.
print(config['Airport']['YMML'].split(','))

Reading Excel files using python3 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to read excel file using python to do some data analysis. The data file is located in the same folder as the python program. However, the code is giving a syntax error. Do not know why. Appreciate your help.
import pandas as pd
dataIn_df = pd.read_excel(r 'C:\Users\Jon\AppData\Local\Programs\Python\data\InputData.xlsx', sheet_name='InputData')
File "C:\Users\Jon\AppData\Local\Programs\Python\data\RateRegulator.py", line 54
dataIn_df = pd.read_excel(r 'C:\Users\Jon\AppData\Local\Programs\Python\data\InputData.xlsx', sheet_name='InputData')
^
SyntaxError: invalid syntax
There is an extra space between r and 'C:\... this is causing the SyntaxError.
r 'C:\Users\Jon\AppData\Local\Programs\Python\data\InputData.xlsx'
should be
r'C:\Users\Jon\AppData\Local\Programs\Python\data\InputData.xlsx'

Python change dir in windows [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I cannot understand, how to read file in different dir on Windows.
>>> import os
>>> os.getcwd()
'C:\\Users\\vasyl.v\\AppData\\Local\\Programs\\Python\\Python37'
>>> Fh = open(“d:\\python\\monitor.py”, “r”)
SyntaxError: invalid character in identifier
Can anyone explain me, how to handle Windows paths in Python 3.7.x?
Try this
with open("d:\\python\\monitor.py", "r") as infile:
# do stuff with file here
data = infile.readlines()
in the code above I used what is called a "context manager", this will automatically close the file when the operations are finished. If the code above does not read your file, then either the path is incorrect, file does not exist, or you dont have proper permissions to read the file.

Categories