Python nested `if else` statements are returning errorsReplacements for switch statement in Python?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?Does Python have a string 'contains' substring method?
What is a scalar particle?
How to move a paragraph and paste it without an initial newline first
What techniques can I use to seduce a PC without arousing suspicion of ulterior motives?
Is it good to put X-Robots-Tag for 410 pages which are still in Google's Index?
Paint numbers from 1 to 8 with two colours
For which would you expect the liquidity on instrument X to be the greatest: its spot, future, option or swap?
Why don't we say a blessing before giving charity?
Why is more music written in sharp keys than flat keys?
What can I use for input conversion instead of scanf?
How short does a trip need to be before flying is less safe than other forms of transportation?
Sci-fi book trilogy about space travel & 'jacking'
How could a sequence of random dates be generated, given year interval?
When to use 8va in musical notation?
Is the ''yoi'' meaning ''ready'' when doing karate the same as the ''yoi'' which means nice/good?
How do I figure out how many hydrogens my compound actually has using a mass and NMR spectrum?
How can an immortal member of the nobility be prevented from taking the throne?
How does kinetic energy work in braking a vehicle?
Why does the Joker do this to Bob?
Why are so many cities in the list of 50 most violent cities in the world located in South and Central America?
Scrum Team and Product Owner working against each other
Why does Bane's stock exchange robbery actually work to bankrupt Bruce Wayne?
What elements would be created in a star composed entirely of gold?
What's the most profitable use for an elemental transmuter?
Why does the SR-71 Blackbird sometimes have dents in the nose?
Python nested `if else` statements are returning errors
Replacements for switch statement in Python?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?Does Python have a string 'contains' substring method?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I am trying to read .txt and .log files, search for specific words and return results to a CSV using if statements. How do I open other files to read in if statements?
I ran the part that's giving me the errors on another python file and it worked fine and was able to open and read. So it's not the code itself I don't think. Although I'm fairly new to Python.
When running the below I get the following error.
latest_file = max(list_of_files, key=os.path.getctime)
ValueError: max() arg is an empty sequence"
with open('//' + hostName + '/C$/Windows/System32/inetsrv/config/applicationHost.config') as doc:
lines1 = doc.read()
if ("logFormat=" + '"W3C"' in lines1):
list_of_files = glob.glob('//' + hostName + '/C$/inetpub/logs/LogFiles/W3SVC1/*')
latest_file = max(list_of_files, key=os.path.getctime)
y = latest_file
with open(y) as doc1:
python
add a comment
|
I am trying to read .txt and .log files, search for specific words and return results to a CSV using if statements. How do I open other files to read in if statements?
I ran the part that's giving me the errors on another python file and it worked fine and was able to open and read. So it's not the code itself I don't think. Although I'm fairly new to Python.
When running the below I get the following error.
latest_file = max(list_of_files, key=os.path.getctime)
ValueError: max() arg is an empty sequence"
with open('//' + hostName + '/C$/Windows/System32/inetsrv/config/applicationHost.config') as doc:
lines1 = doc.read()
if ("logFormat=" + '"W3C"' in lines1):
list_of_files = glob.glob('//' + hostName + '/C$/inetpub/logs/LogFiles/W3SVC1/*')
latest_file = max(list_of_files, key=os.path.getctime)
y = latest_file
with open(y) as doc1:
python
5
the error is telling you thatlist_of_files
has no items, double check that your path to the files is constructed properly
– aws_apprentice
Mar 28 at 17:07
1
When I used glob.glob, I remmember it was only a list of filenames, I had to concatenate path+file to open them, probably you have the same problem. Debug is your new best friend
– Wonka
Mar 28 at 17:15
add a comment
|
I am trying to read .txt and .log files, search for specific words and return results to a CSV using if statements. How do I open other files to read in if statements?
I ran the part that's giving me the errors on another python file and it worked fine and was able to open and read. So it's not the code itself I don't think. Although I'm fairly new to Python.
When running the below I get the following error.
latest_file = max(list_of_files, key=os.path.getctime)
ValueError: max() arg is an empty sequence"
with open('//' + hostName + '/C$/Windows/System32/inetsrv/config/applicationHost.config') as doc:
lines1 = doc.read()
if ("logFormat=" + '"W3C"' in lines1):
list_of_files = glob.glob('//' + hostName + '/C$/inetpub/logs/LogFiles/W3SVC1/*')
latest_file = max(list_of_files, key=os.path.getctime)
y = latest_file
with open(y) as doc1:
python
I am trying to read .txt and .log files, search for specific words and return results to a CSV using if statements. How do I open other files to read in if statements?
I ran the part that's giving me the errors on another python file and it worked fine and was able to open and read. So it's not the code itself I don't think. Although I'm fairly new to Python.
When running the below I get the following error.
latest_file = max(list_of_files, key=os.path.getctime)
ValueError: max() arg is an empty sequence"
with open('//' + hostName + '/C$/Windows/System32/inetsrv/config/applicationHost.config') as doc:
lines1 = doc.read()
if ("logFormat=" + '"W3C"' in lines1):
list_of_files = glob.glob('//' + hostName + '/C$/inetpub/logs/LogFiles/W3SVC1/*')
latest_file = max(list_of_files, key=os.path.getctime)
y = latest_file
with open(y) as doc1:
python
python
edited Mar 28 at 17:37
Shakespear
1,0873 gold badges14 silver badges21 bronze badges
1,0873 gold badges14 silver badges21 bronze badges
asked Mar 28 at 17:05
J TJ T
221 silver badge6 bronze badges
221 silver badge6 bronze badges
5
the error is telling you thatlist_of_files
has no items, double check that your path to the files is constructed properly
– aws_apprentice
Mar 28 at 17:07
1
When I used glob.glob, I remmember it was only a list of filenames, I had to concatenate path+file to open them, probably you have the same problem. Debug is your new best friend
– Wonka
Mar 28 at 17:15
add a comment
|
5
the error is telling you thatlist_of_files
has no items, double check that your path to the files is constructed properly
– aws_apprentice
Mar 28 at 17:07
1
When I used glob.glob, I remmember it was only a list of filenames, I had to concatenate path+file to open them, probably you have the same problem. Debug is your new best friend
– Wonka
Mar 28 at 17:15
5
5
the error is telling you that
list_of_files
has no items, double check that your path to the files is constructed properly– aws_apprentice
Mar 28 at 17:07
the error is telling you that
list_of_files
has no items, double check that your path to the files is constructed properly– aws_apprentice
Mar 28 at 17:07
1
1
When I used glob.glob, I remmember it was only a list of filenames, I had to concatenate path+file to open them, probably you have the same problem. Debug is your new best friend
– Wonka
Mar 28 at 17:15
When I used glob.glob, I remmember it was only a list of filenames, I had to concatenate path+file to open them, probably you have the same problem. Debug is your new best friend
– Wonka
Mar 28 at 17:15
add a comment
|
1 Answer
1
active
oldest
votes
Apparently it was working for most hostnames. I added the try and except statements and caught the errors.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403254%2fpython-nested-if-else-statements-are-returning-errors%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Apparently it was working for most hostnames. I added the try and except statements and caught the errors.
add a comment
|
Apparently it was working for most hostnames. I added the try and except statements and caught the errors.
add a comment
|
Apparently it was working for most hostnames. I added the try and except statements and caught the errors.
Apparently it was working for most hostnames. I added the try and except statements and caught the errors.
answered Mar 28 at 21:38
J TJ T
221 silver badge6 bronze badges
221 silver badge6 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403254%2fpython-nested-if-else-statements-are-returning-errors%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
5
the error is telling you that
list_of_files
has no items, double check that your path to the files is constructed properly– aws_apprentice
Mar 28 at 17:07
1
When I used glob.glob, I remmember it was only a list of filenames, I had to concatenate path+file to open them, probably you have the same problem. Debug is your new best friend
– Wonka
Mar 28 at 17:15