[Tutor] Tutor Digest, Vol 127, Issue 12
Najam Qasim
najam.qasim at yahoo.com
Thu Sep 4 22:37:57 CEST 2014
I downloaded notepad++. Can you please help me how to run python script in notepad++?
Thanks.
Najam
> On Sep 4, 2014, at 4:23 PM, tutor-request at python.org wrote:
>
> Send Tutor mailing list submissions to
> tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-request at python.org
>
> You can reach the person managing the list at
> tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
> 1. New to Python..Need help (Felisha Lawrence)
> 2. Re: New to Python..Need help (Joel Goldstick)
> 3. Re: New to Python..Need help (taserian)
> 4. Re: New to Python..Need help (Alan Gauld)
> 5. Re: New to Python..Need help (Danny Yoo)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 4 Sep 2014 08:49:04 -0400
> From: Felisha Lawrence <felisha.lawrence at gmail.com>
> To: tutor at python.org
> Subject: [Tutor] New to Python..Need help
> Message-ID:
> <CALcsL=HKbO6PyORkERpzVpgHJ+d2+aT1bXhQd7W7gbnHf6cXQQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hello,
> I have a question regarding strings in python. I have a directory on my
> MacBook Bro of about 13 files. I need to alter the file endings in
> that directory. The files are on the order of
> 'swp.113006004000_KLWX_0.0.5_PPI_v2','swp.113006004000_KLWX_0.0.5_PPI_v3'.
> I need to remove the characters after the 'v' and replace with v20. All of
> the endings of the files are sequential _v2, _v3,_v4, _v5. I need all of
> these characters to be the same (i.e. v20). I would like to know which
> modules are best to use, and how to use loops to alter them. Any help you
> can provide would be great.
>
>
> Thanks,
> Felisha Lawrence
>
> --
> Felisha Lawrence
> Howard University Program for Atmospheric Sciences(HUPAS), Graduate Student
>
> NASA URC/BCCSO Graduate Fellow
> NOAA NCAS Graduate Fellow
> Graduate Student Association for Atmospheric Sciences(GSAAS), Treasurer
> (240)-535-6665 (cell)
> felisha.lawrence at gmail.com (email)
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/tutor/attachments/20140904/046d8eee/attachment-0001.html>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 4 Sep 2014 15:01:50 -0400
> From: Joel Goldstick <joel.goldstick at gmail.com>
> Cc: "tutor at python.org" <tutor at python.org>
> Subject: Re: [Tutor] New to Python..Need help
> Message-ID:
> <CAPM-O+xc==QxPNBNPALkr75zivANyx1ewXPiRia4s88a5yruFA at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> On Thu, Sep 4, 2014 at 8:49 AM, Felisha Lawrence
> <felisha.lawrence at gmail.com> wrote:
>> Hello,
>> I have a question regarding strings in python. I have a directory on my
>> MacBook Bro of about 13 files. I need to alter the file endings in that
>> directory. The files are on the order of
>> 'swp.113006004000_KLWX_0.0.5_PPI_v2','swp.113006004000_KLWX_0.0.5_PPI_v3'. I
>> need to remove the characters after the 'v' and replace with v20. All of the
>> endings of the files are sequential _v2, _v3,_v4, _v5. I need all of these
>> characters to be the same (i.e. v20). I would like to know which modules are
>> best to use, and how to use loops to alter them. Any help you can provide
>> would be great.
> Check out the documentation for os.walk and os.rename. The first to
> collect you filenames, and the second to rename them.
>
>> Thanks,
>> Felisha Lawrence
>>
>> --
>> Felisha Lawrence
>> Howard University Program for Atmospheric Sciences(HUPAS), Graduate Student
>> NASA URC/BCCSO Graduate Fellow
>> NOAA NCAS Graduate Fellow
>> Graduate Student Association for Atmospheric Sciences(GSAAS), Treasurer
>> (240)-535-6665 (cell)
>> felisha.lawrence at gmail.com (email)
>>
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com
>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 4 Sep 2014 15:05:32 -0400
> From: taserian <taserian at gmail.com>
> To: Felisha Lawrence <felisha.lawrence at gmail.com>
> Cc: Tutor <tutor at python.org>
> Subject: Re: [Tutor] New to Python..Need help
> Message-ID:
> <CAOgHRJOG7881LUSswgHG0n324YPJCXPKOqBxZnqztBQsd1xcrg at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Is there anything different between the filenames aside from that suffix
> _vXX? If not, then you'll run into problems after the first filename is
> changed; further attempts won't allow the change, since there's already a
> file with that same name.
>
> AR
>
>
> On Thu, Sep 4, 2014 at 8:49 AM, Felisha Lawrence <felisha.lawrence at gmail.com
>> wrote:
>
>> Hello,
>> I have a question regarding strings in python. I have a directory on my
>> MacBook Bro of about 13 files. I need to alter the file endings in
>> that directory. The files are on the order of
>> 'swp.113006004000_KLWX_0.0.5_PPI_v2','swp.113006004000_KLWX_0.0.5_PPI_v3'.
>> I need to remove the characters after the 'v' and replace with v20. All of
>> the endings of the files are sequential _v2, _v3,_v4, _v5. I need all of
>> these characters to be the same (i.e. v20). I would like to know which
>> modules are best to use, and how to use loops to alter them. Any help you
>> can provide would be great.
>>
>>
>> Thanks,
>> Felisha Lawrence
>>
>> --
>> Felisha Lawrence
>> Howard University Program for Atmospheric Sciences(HUPAS), Graduate
>> Student
>> NASA URC/BCCSO Graduate Fellow
>> NOAA NCAS Graduate Fellow
>> Graduate Student Association for Atmospheric Sciences(GSAAS), Treasurer
>> (240)-535-6665 (cell)
>> felisha.lawrence at gmail.com (email)
>>
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/tutor/attachments/20140904/066af7b1/attachment-0001.html>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 04 Sep 2014 20:16:04 +0100
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] New to Python..Need help
> Message-ID: <luadpk$7dc$1 at ger.gmane.org>
> Content-Type: text/plain; charset=windows-1252; format=flowed
>
>> On 04/09/14 13:49, Felisha Lawrence wrote:
>>
>> 'swp.113006004000_KLWX_0.0.5_PPI_v2','swp.113006004000_KLWX_0.0.5_PPI_v3'.
>> I need to remove the characters after the 'v' and replace with v20. All of
>> the endings of the files are sequential _v2, _v3,_v4, _v5. I need all of
>> these characters to be the same (i.e. v20).
>
> How else will you differentiate them if the files are all the same? Do
> you need to add a sequence number or do you really want to concateate
> the files into one big file?
>
>> I would like to know which
>> modules are best to use, and how to use loops to alter them.
>
> You can use os.listdir to get all the filenames in a single folder
>
> You can use glob.glob to get a subset of the files
> (using * and ? as wildvards)
>
> You can use os.walk to get all the files/folders from a directry tree
>
>
> Once you have the list of files you can use a for loop to access each name.
>
> You can the use
>
> string.replace() to make simple changes
> re.sub() to replace regular expressions
>
> Or you could use string slicing to replace certain characters
> based on position, wjhich might work well for your case.
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
>
>
> ------------------------------
>
> Message: 5
> Date: Thu, 4 Sep 2014 13:22:35 -0700
> From: Danny Yoo <dyoo at hashcollision.org>
> To: Felisha Lawrence <felisha.lawrence at gmail.com>
> Cc: Python Tutor Mailing List <tutor at python.org>
> Subject: Re: [Tutor] New to Python..Need help
> Message-ID:
> <CAGZAPF4HHf96TY+_XFvpodF+qJGTAxm-9SRp0upZNRyp9kj=tA at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
>> I have a question regarding strings in python. I have a directory on my
>> MacBook Bro of about 13 files. I need to alter the file endings in that
>> directory. The files are on the order of
>> 'swp.113006004000_KLWX_0.0.5_PPI_v2','swp.113006004000_KLWX_0.0.5_PPI_v3'. I
>> need to remove the characters after the 'v' and replace with v20. All of the
>> endings of the files are sequential _v2, _v3,_v4, _v5. I need all of these
>> characters to be the same (i.e. v20). I would like to know which modules are
>> best to use, and how to use loops to alter them. Any help you can provide
>> would be great.
>
> Hi Felisha,
>
>
> Do you have any prior programming experience?
>
> Your subject line suggests that you are new to Python. Are you
> familiar with any other programming? Give us more details, and we may
> be able to provide more appropriate advice. In lack of background
> information, we will assume for the moment that you have some basic
> programming skills, and will point to documentation where appropriate.
>
>
> We can point to:
>
> https://docs.python.org/2/tutorial/
>
> to get a quick-and-dirty introduction to the language.
>
>
>
> For the operations you'll be doing, you probably want:
>
> 1. Some way to collect the set of file names. The glob module might
> be appropriate:
>
> https://docs.python.org/2/library/glob.html
>
>
> 2. Basic string manipulation skills to map the string:
>
> "swp.113006004000_KLWX_0.0.5_PPI_v2"
>
> to its replacement string:
>
> "swp.113006004000_KLWX_0.0.5_PPI_v20"
>
>
> For this particular pattern matching and string replacement, it might
> be enough to find the rightmost index for the substring "_v" using a
> string's rfind() method:
>
> https://docs.python.org/2/library/stdtypes.html#str.rfind
>
> string slicing (https://docs.python.org/2/tutorial/introduction.html#strings)
> to chop off the tail, and then a string append to put the replacement
> "_v20" at the end.
>
>
> For anything more sophisticated, you might want to investigate regular
> expressions.
>
> https://docs.python.org/2/howto/regex.html
>
>
> 3. Functions to interact with the operating system, to tell the
> operating system to rename a file from the old name to its
> replacement. Possibly os.rename():
>
> https://docs.python.org/2/library/os.html#os.rename
>
>
>
> Please feel free to ask more questions. Good luck!
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> End of Tutor Digest, Vol 127, Issue 12
> **************************************
More information about the Tutor
mailing list