38782

How to prevent f.write to output the number of characters written?

Question:

I use Python3 and write result into a file like this:

with open(output,'w') as f: f.write('Line count of the log files is: ' + str(line_count) + '. \n')

f.write() automatically returns # of characters written, is there a way to do not output it? I ask this because I do not want it output.

Thanks.

Answer1:

This is not unique to file.write(). The interactive interpreter prints the result of any evaluated expression that does not result in None.

>>> for i in range(3): ... i # expression evaluates to the value of i ... 0 1 2 >>>

Two things to note. First, these won't be displayed when you are not using the interactive interpreter, so it's safe to ignore.

Second, you can make the display go away by assigning the result. That turns the expression into a statement.

>>> for i in range(3): ... _ = i # underscore is a nice meaningless variable name ... >>>

Recommend

  • Can't seem to save the markup version of the text using wmd-editor
  • post multi-select list to list of objects asp.net core 2
  • How to clone bootstrap multi-select dynamically?
  • How to copy file to local directory using Ansible?
  • Apache Flink Streaming window WordCount
  • How application get update from apple store?
  • changing src attributes
  • How to use a Git repository with multiple projects?
  • WooCommerce Free Shipping - Remove raw or change the text name on checkout and email
  • Excel VBA: Forward ParamArray to Application.Run
  • How to remove item from Panel
  • CSS button not styling
  • Stop the background service after particular time in android
  • Sending in an object of type Object instead of String - Polymorphism
  • JQuery and PHP validation problem?
  • limit python input to int
  • Reveal Icon Button - Bootstrap 3
  • How to resume hash slots of a particular node in redis cluster in case of hard failure?
  • I have a problem with the Fetch API using Internet Explorer 11
  • Spring Cloud Config - Multiple Composite Repositories?
  • OpenCV::solvePNP() - Assertion failed
  • Xmlserializer to C# object, store original XML element
  • How to process remote XML files with XSLT
  • Issue with Terrain Collision using Three.js
  • JQuery Mobile Ajax Navigation in Single-Page Template
  • Slice assignment to tensorflow variable
  • What are advantages/disadvantages of using Selenium for Java vs .NET applications?
  • Set SelectedIndex of ListView in FlipView_SelectionChanged event
  • Year over Year Stats from a Crossfilter Dataset
  • openpyxl - adding new rows in excel file with merged cell existing
  • Add font awesome icon to custom add to cart button in Woocommerce 3
  • How to write seo friendly url's using htaccess?
  • Django, uWSGI & nginx: Process dies for “no reason”
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • Neo4j…how to get a visual representation of my data?
  • Using Service Component Runtime
  • Firebase: How to read from external DB?
  • Write to .csv file with PHP (Commas in Data Error)
  • convert json to excel in java