#pythonVersion One line of content output by line
a="aa1 one bb2 two cc3 three dd4 four ee5 five ff6 six gg7 seven hh8 eight ii9 nine" "" " The branch output is: abcdefghi abcdefghi 123456789 one two three four five six seven eight nine "" " print ("Method one:================") for r in range (0,4): t="" for s in range (0 + r, len (a), 4): t=t + a [s] print (t) print ("Method two:================) #=_=Will this method look stupid? l=list (a) ta=tb=tc=td="" for r in range (0,9): for s in range (0,4): if s == 0: ta=ta + l.pop (0) if s == 1: tb=tb + l.pop (0) if s == 2: tc=tc+ l.pop (0) if s == 3: td=td + l.pop (0) print (ta) print (tb) print (tc) print (td) print ("Method 3:There are n ways to write back characters ===============") import string ta=tb=tc=td="" la=string.ascii_lowercase ua=string.ascii_uppercase nb=string.digits ub="One Two Three Four Five Six Seven Eight Nine" for s in a: if s in la: ta=ta + s if s in ua: tb=tb + s if s in nb: tc=tc+ s if s in ub: td=td + s print (ta) print (tb) print (tc) print (td) print ("Method 4:Echoes have a way of writing regular expressions =============== '') import re #This regular writing feels unscientific,No good ideas for now reg=["[a-z]", "[a-z]", "\ d", "[^ \ da-za-z]"] for s in reg: rega=re.compile (s) s=re.findall (rega, a) print ("". join (s)) "" " Output: Method 1:================ abcdefghi abcdefghi 123456789 one two three four five six seven eight nine Method 2:================ abcdefghi abcdefghi 123456789 one two three four five six seven eight nine Method 3:There are n ways to write back words ================ abcdefghi abcdefghi 123456789 one two three four five six seven eight nine Method 4:There is a wording called regex =============== abcdefghi abcdefghi 123456789 one two three four five six seven eight nine "" "
Give you a method to read the content of the file and output it in separate lines.
f=open ("shuju.txt", "r") content=f.read () print content for i in content: print i f.close () f=open ("shuju.txt", "w") f.write (content) f.close ()
Well, the little friends study it yourself.Interesting.
- Example of Python using re module to extract content in parentheses in a string
- Analysis of Modifying File Contents in Python
- Python implementation delete line with "specified content" in file example
- Python file operations, open read and write files, append text content examples
- Python extract the specified content instance based on regular expressions
- Python batch modification method of text file content
- Method for sending form-data request and stitching form-data content in Python
- Explain how to parse and modify XML content in Python programs
- Stealing roommate's USB stick content with 11 lines of Python code
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- dart - flutter: the instance member'stars' can't be accessed in an initializer error