Stripping and renaming filesHow do I check whether a file exists without exceptions?How do I copy a file in Python?How do I list all files of a directory?How to read a file line-by-line into a list?Delete a file or folderHow to read a text file into a string variable and strip newlines?Renaming columns in pandasHow do I write JSON data to a file?How to prettyprint a JSON file?Python logging typeerror

A faster way to compute the largest prime factor

Double-nominative constructions and “von”

All ASCII characters with a given bit count

Bayes factor vs P value

What does "function" actually mean in music?

Older movie/show about humans on derelict alien warship which refuels by passing through a star

A Paper Record is What I Hamper

Restricting the options of a lookup field, based on the value of another lookup field?

How do I reattach a shelf to the wall when it ripped out of the wall?

Is Diceware more secure than a long passphrase?

std::unique_ptr of base class holding reference of derived class does not show warning in gcc compiler while naked pointer shows it. Why?

Can a stored procedure reference the database in which it is stored?

Is there metaphorical meaning of "aus der Haft entlassen"?

Are there moral objections to a life motivated purely by money? How to sway a person from this lifestyle?

Scheduling based problem

How much cash can I safely carry into the USA and avoid civil forfeiture?

Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?

How long after the last departure shall the airport stay open for an emergency return?

What is this word supposed to be?

Work requires me to come in early to start computer but wont let me clock in to get paid for it

Contradiction proof for inequality of P and NP?

How do I produce this symbol: Ϟ in pdfLaTeX?

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

Help with my training data



Stripping and renaming files


How do I check whether a file exists without exceptions?How do I copy a file in Python?How do I list all files of a directory?How to read a file line-by-line into a list?Delete a file or folderHow to read a text file into a string variable and strip newlines?Renaming columns in pandasHow do I write JSON data to a file?How to prettyprint a JSON file?Python logging typeerror






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have written some Python modifying existing code to run through some JSON files and strip out some text. The end result should be saving the now edited file with the same file name "- clean.json" at the end.



I already have the code that loops through the input path, and all JSON files complete. I have also completed and tested that each file does open and the desired text is removed.



The final area is where I need help, how do I now take that updated file and save it back with an updated name. That updated name being -clean.json



All help is appreciated, script is included below:



def normalize_file(file):
global line_number
for line in file:
line_number += 1
json_object = json.loads(line)
logging.info("hi")
if not isinstance(json_object, dict):
logging.error('%s: Top level record must be a dict but was a %s',
line_number, type(json_object))
continue
try:
normalized_dict = normalize_dict(json_object)
except Exception as e:
logging.error('%s: %s', line_number, e)
continue
json.dump(normalized_dict, sys.stdout)
print()
logging.info("Processed %s lines", line_number)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logging.info("hi")
input_path = input("Enter path to JSON files->")
json_folder_path = os.path.join(input_path)
json_files = [pos_json for pos_json in os.listdir(input_path) if pos_json.endswith('.json')]
print(json_files)
for index, js in enumerate(json_files):
with open(os.path.join(input_path,js)) as json_file:
normalize_file(json_file)









share|improve this question
























  • Please reduce your code to a minimum, highlighting where exactly you need help. As it is, your code has several issues - it is unclear which one you need help with. For example, you ignore the user input, defying 1. You never open any files, so how do you know that 3 is working? You are loading several JSON from each file in a fragile manner, but your description implies otherwise.

    – MisterMiyagi
    Mar 22 at 16:40







  • 1





    @MisterMiyagi - understood, i have posted my updated code. the main body and function it calls only. I have also simplified the question I believe. Thanks for your feedback.

    – SSISPissesMeOff
    Mar 22 at 17:27

















0















I have written some Python modifying existing code to run through some JSON files and strip out some text. The end result should be saving the now edited file with the same file name "- clean.json" at the end.



I already have the code that loops through the input path, and all JSON files complete. I have also completed and tested that each file does open and the desired text is removed.



The final area is where I need help, how do I now take that updated file and save it back with an updated name. That updated name being -clean.json



All help is appreciated, script is included below:



def normalize_file(file):
global line_number
for line in file:
line_number += 1
json_object = json.loads(line)
logging.info("hi")
if not isinstance(json_object, dict):
logging.error('%s: Top level record must be a dict but was a %s',
line_number, type(json_object))
continue
try:
normalized_dict = normalize_dict(json_object)
except Exception as e:
logging.error('%s: %s', line_number, e)
continue
json.dump(normalized_dict, sys.stdout)
print()
logging.info("Processed %s lines", line_number)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logging.info("hi")
input_path = input("Enter path to JSON files->")
json_folder_path = os.path.join(input_path)
json_files = [pos_json for pos_json in os.listdir(input_path) if pos_json.endswith('.json')]
print(json_files)
for index, js in enumerate(json_files):
with open(os.path.join(input_path,js)) as json_file:
normalize_file(json_file)









share|improve this question
























  • Please reduce your code to a minimum, highlighting where exactly you need help. As it is, your code has several issues - it is unclear which one you need help with. For example, you ignore the user input, defying 1. You never open any files, so how do you know that 3 is working? You are loading several JSON from each file in a fragile manner, but your description implies otherwise.

    – MisterMiyagi
    Mar 22 at 16:40







  • 1





    @MisterMiyagi - understood, i have posted my updated code. the main body and function it calls only. I have also simplified the question I believe. Thanks for your feedback.

    – SSISPissesMeOff
    Mar 22 at 17:27













0












0








0








I have written some Python modifying existing code to run through some JSON files and strip out some text. The end result should be saving the now edited file with the same file name "- clean.json" at the end.



I already have the code that loops through the input path, and all JSON files complete. I have also completed and tested that each file does open and the desired text is removed.



The final area is where I need help, how do I now take that updated file and save it back with an updated name. That updated name being -clean.json



All help is appreciated, script is included below:



def normalize_file(file):
global line_number
for line in file:
line_number += 1
json_object = json.loads(line)
logging.info("hi")
if not isinstance(json_object, dict):
logging.error('%s: Top level record must be a dict but was a %s',
line_number, type(json_object))
continue
try:
normalized_dict = normalize_dict(json_object)
except Exception as e:
logging.error('%s: %s', line_number, e)
continue
json.dump(normalized_dict, sys.stdout)
print()
logging.info("Processed %s lines", line_number)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logging.info("hi")
input_path = input("Enter path to JSON files->")
json_folder_path = os.path.join(input_path)
json_files = [pos_json for pos_json in os.listdir(input_path) if pos_json.endswith('.json')]
print(json_files)
for index, js in enumerate(json_files):
with open(os.path.join(input_path,js)) as json_file:
normalize_file(json_file)









share|improve this question
















I have written some Python modifying existing code to run through some JSON files and strip out some text. The end result should be saving the now edited file with the same file name "- clean.json" at the end.



I already have the code that loops through the input path, and all JSON files complete. I have also completed and tested that each file does open and the desired text is removed.



The final area is where I need help, how do I now take that updated file and save it back with an updated name. That updated name being -clean.json



All help is appreciated, script is included below:



def normalize_file(file):
global line_number
for line in file:
line_number += 1
json_object = json.loads(line)
logging.info("hi")
if not isinstance(json_object, dict):
logging.error('%s: Top level record must be a dict but was a %s',
line_number, type(json_object))
continue
try:
normalized_dict = normalize_dict(json_object)
except Exception as e:
logging.error('%s: %s', line_number, e)
continue
json.dump(normalized_dict, sys.stdout)
print()
logging.info("Processed %s lines", line_number)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logging.info("hi")
input_path = input("Enter path to JSON files->")
json_folder_path = os.path.join(input_path)
json_files = [pos_json for pos_json in os.listdir(input_path) if pos_json.endswith('.json')]
print(json_files)
for index, js in enumerate(json_files):
with open(os.path.join(input_path,js)) as json_file:
normalize_file(json_file)






python json python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 17:26







SSISPissesMeOff

















asked Mar 22 at 16:36









SSISPissesMeOffSSISPissesMeOff

1301214




1301214












  • Please reduce your code to a minimum, highlighting where exactly you need help. As it is, your code has several issues - it is unclear which one you need help with. For example, you ignore the user input, defying 1. You never open any files, so how do you know that 3 is working? You are loading several JSON from each file in a fragile manner, but your description implies otherwise.

    – MisterMiyagi
    Mar 22 at 16:40







  • 1





    @MisterMiyagi - understood, i have posted my updated code. the main body and function it calls only. I have also simplified the question I believe. Thanks for your feedback.

    – SSISPissesMeOff
    Mar 22 at 17:27

















  • Please reduce your code to a minimum, highlighting where exactly you need help. As it is, your code has several issues - it is unclear which one you need help with. For example, you ignore the user input, defying 1. You never open any files, so how do you know that 3 is working? You are loading several JSON from each file in a fragile manner, but your description implies otherwise.

    – MisterMiyagi
    Mar 22 at 16:40







  • 1





    @MisterMiyagi - understood, i have posted my updated code. the main body and function it calls only. I have also simplified the question I believe. Thanks for your feedback.

    – SSISPissesMeOff
    Mar 22 at 17:27
















Please reduce your code to a minimum, highlighting where exactly you need help. As it is, your code has several issues - it is unclear which one you need help with. For example, you ignore the user input, defying 1. You never open any files, so how do you know that 3 is working? You are loading several JSON from each file in a fragile manner, but your description implies otherwise.

– MisterMiyagi
Mar 22 at 16:40






Please reduce your code to a minimum, highlighting where exactly you need help. As it is, your code has several issues - it is unclear which one you need help with. For example, you ignore the user input, defying 1. You never open any files, so how do you know that 3 is working? You are loading several JSON from each file in a fragile manner, but your description implies otherwise.

– MisterMiyagi
Mar 22 at 16:40





1




1





@MisterMiyagi - understood, i have posted my updated code. the main body and function it calls only. I have also simplified the question I believe. Thanks for your feedback.

– SSISPissesMeOff
Mar 22 at 17:27





@MisterMiyagi - understood, i have posted my updated code. the main body and function it calls only. I have also simplified the question I believe. Thanks for your feedback.

– SSISPissesMeOff
Mar 22 at 17:27












0






active

oldest

votes












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/3.0/"u003ecc by-sa 3.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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304120%2fstripping-and-renaming-files%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304120%2fstripping-and-renaming-files%23new-answer', 'question_page');

);

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







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해