Trying to learn python


 
Thread Tools Search this Thread
Top Forums Programming Trying to learn python
# 1  
Old 10-16-2013
Trying to learn python

Hi ,

This is my 1st program in python never tried any python before.

i am trying to write a python script which reads a .tsv file line by line and in each line it should look for mm/dd/yyyy formate and replace it with yyyy/mm/dd formate . can some one provide be some sample code to do that.

Code:
f = open("test.txt","r") 
for line in f:
    ----------
-----------------
--------------------
print(myList

# 2  
Old 10-17-2013
Code:
#!/usr/bin/python

import re

# open file in read mode
f = open('test.txt', 'r')

# compile a pattern to match the date string
p = re.compile(r'(\d{,2})\/(\d{,2})\/(\d{4})')

# loop through file and replace date string with
# new format
for line in f.readlines():
    line = re.sub(p, r'\3/\1/\2', line)
    print line

# close the file
f.close()

9987f6e1fd5f0913bb22e646bee1e2f9

Last edited by in2nix4life; 11-12-2013 at 02:37 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies

2. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Programming

Any Good resources to learn Python

Hi Guys, I will be doing my masters in Comp science in a few months. I would like to get intimate with python by ideally doing a project based tutorial. Is there any good resource for learning python with an end project in mind. ? (4 Replies)
Discussion started by: srkmish
4 Replies

4. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. SuSE

"ssh suse-server 'python -V' > python-version.out" not redirecting

Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here. I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
Discussion started by: Druonysus
3 Replies

6. UNIX for Dummies Questions & Answers

Want to learn

Hi I know only basics of UNIX and i want to know that how can i become a good troubleshooter in unix adminstartion or shell scripting.... i am just a newbie to Unix ..i do not have programming skills as well. Your suggestions are welecomed. (1 Reply)
Discussion started by: nattynitin
1 Replies

7. UNIX for Dummies Questions & Answers

I Want to Learn HP-UX!

What's the best free system to learn HP-UX on? The closest system, hardware requirements and installation instructions. I'm a newbie but determined. Any tips would be great. (6 Replies)
Discussion started by: networkguy
6 Replies

8. UNIX for Dummies Questions & Answers

I want to learn!

Hiya, yes im new to all of this! But want to learn how to use Unix etc, iv been thinking about doin a course but desided im better off learning by my self with help from the people who really no what there doin...you guys! I can install Linux, like redhat, mandrake, susie server edition and so... (5 Replies)
Discussion started by: epic.admin
5 Replies

9. UNIX for Dummies Questions & Answers

Where to Learn About HP-UX

can someone give me the link to any site that deals on HP-UX system administration?? Please do not refer me to buy or borrow any books, i just need a free site to learn some quick info from (1 Reply)
Discussion started by: TRUEST
1 Replies
Login or Register to Ask a Question