Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 11th, 2012, 02:44 PM
Newbie708 Newbie708 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 Newbie708 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 12 sec
Reputation Power: 0
Help combining files

Hello,

I am trying to take all the files in my folder proteinsequences and combine them all into one file. I have been on the nternet trying to find other peoples programs. This one seems like it should work but I get a syntax error. The arrow points to the =. in "print(l, file = out)" Any suggestions?

#set to the file extension of "to-be-merged" files
ext='._ALL'
#set to your working directory
dir_path='/home/bonita/Documents/proteinsequences'
#set to the name of your output file
results='NB_protein.fasta'

import os
files=os.listdir(dir_path)
for f in files:
if f.endswith(ext):
data = open(f)
out = open(results, 'w')
for l in data:
print(l, file = out)
data.close()
out.close()

Reply With Quote
  #2  
Old October 11th, 2012, 03:15 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,372 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 11 h 39 m 38 sec
Reputation Power: 383
Sure,
the code you posted is a python3 code. It won't work in python2.

Hmm, it has recently been shown to me that you might be able to import print_function from the future.

from __future__ import print_function


But why are you writing a program?

in unix, and it looks like you've got a unixy system, the command is:

$ cat *._ALL > NB_protein.fasta

I'm not going to bother checking what the DOS command is, but it's probably

A:> copy *._ALL NB_protein.fasta
[insert new floppy for A:]
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old October 11th, 2012, 03:51 PM
Purity_Lake Purity_Lake is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 33 Purity_Lake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 25 m 17 sec
Reputation Power: 2
b49P23TIvg is right, no point writing a program that is already done by dos or terminal

but to answer your question your problem is you print(l, file = out), this doesn't work this way at least not to my knowledge use something like the following
Code:
file = open('INFORMATION.txt', 'w')
a_file = open('MORE_INFORMATION.txt', 'w')
results = open('RESULTS.txt', 'w')

results.writeline("%s\n" % for item in file)

results.writeline("%s\n" % for item in a_file)

file.close()
a_file.close()
results.close()


That should be good enough to give you an idea of what you need to do. hope this has helped good luck with python

Reply With Quote
  #4  
Old October 11th, 2012, 08:20 PM
Newbie708 Newbie708 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 Newbie708 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 12 sec
Reputation Power: 0
Cool Thanks!

Thank you for the help guys.

You were right I just used the cat *>file command in the terminal. The only reason I was trying to code it is because I didn't know it was so easily done.


Thank you again for the help!

Reply With Quote
  #5  
Old October 12th, 2012, 11:05 AM
Purity_Lake Purity_Lake is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 33 Purity_Lake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 25 m 17 sec
Reputation Power: 2
no problem

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help combining files

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap