Python-related file methods

Source: Internet
Author: User

The tell () method tells you the current position within the file, in other words, the next read and write occurs after so many bytes at the beginning of the file:

The Seek (offset [, from]) method changes the position of the current file. The offset variable represents the number of bytes to move. The from variable specifies the reference position at which to begin moving bytes.


ChDir () method

You can use the ChDir () method to change the current directory. The ChDir () method requires a parameter that you want to set as the directory name of the current directory.

Grammar:

Os.chdir ("Newdir")

Example:

The following example goes to the "/home/newdir" directory.

#!/usr/bin/python

Import OS

# Change the current directory to "/home/newdir"

Os.chdir ("/home/newdir")


GETCWD () Method:

The GETCWD () method displays the current working directory.


Grammar:

OS.GETCWD ()

Example:

The following example gives the current directory:

#!/usr/bin/python

Import OS

# give the current directory

OS.GETCWD ()


This article is from the DBA Sky blog, so be sure to keep this source http://9425473.blog.51cto.com/9415473/1693781

Python-related file methods

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.