Sponsored Content
Full Discussion: Python Concatenating 2 Lists
Top Forums Programming Python Concatenating 2 Lists Post 302932336 by totoro125 on Tuesday 20th of January 2015 09:19:44 PM
Old 01-20-2015
Python Concatenating 2 Lists

I am just trying to concatenate two lists together, but I am not sure what is wrong with my code, it won't run. Thank you for any help.

Code:
#!/usr/bin/python
# Takes two lists and returns a list that is the concatenation of both of
# them.

A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
B = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
def list_concat( A, B):

   print(A)
   print(B)
   A.extend(B)
   print(A)

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script to Create non-duplicate lists from two lists

File_A contains Strings: a b c d File_B contains Strings: a c z Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below. Resultant... (7 Replies)
Discussion started by: mlv_99
7 Replies

2. Shell Programming and Scripting

need help in concatenating

Hi All , i`m writing a script , i stucked in middle . Script echo "Please Enter the INSTANCE name" read iName echo "The INSTANCE name is $iName" more /opt/IBMIHS*/conf/httpd.conf_"$iName" script end here i`m getting error as : Error /opt/IBMIHS*/conf/httpd.conf_w101:... (7 Replies)
Discussion started by: radha254
7 Replies

3. Programming

Python: Compare 2 word lists

Hi. I am trying to write a Python programme that compares two different text files which both contain a list of words. Each word has its own line worda wordb wordc I want to compare textfile 2 with textfile 1, and if there's a word in textfile 2 that is NOT in textfile 1, I want to... (6 Replies)
Discussion started by: Bloomy
6 Replies

4. Homework & Coursework Questions

[Python] Compare 2 lists

Hello, I'm new to the python programming, and I have a question. I have to write a program that prints a receipt for a restaurant. The input is a list which looks like: product1 product3 product8 .... In the other input file there is a list which looks like: product1 coffee 5,00... (1 Reply)
Discussion started by: dagendy
1 Replies

5. Shell Programming and Scripting

Separate Text File into Two Lists Using Python

Hello, I have a pretty simple question, but I am new to Python and am trying to write a simple program. Put simply, I want to take a text file that looks like this: 11111 22222 33333 44444 55555 66666 77777 88888 and produce two lists, one containing the contents of the left column, one the... (0 Replies)
Discussion started by: Tyler_92
0 Replies

6. Programming

Populating Lists in Def using Python

Dipping around in python again and need to create a def that will populate a list(content) with the files that os.walk finds from within this directory and then I will re.search through each files looking for content. In learning Python, can someone point me in the right direction. This is what I... (3 Replies)
Discussion started by: metallica1973
3 Replies

7. 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

8. 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

9. 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
dpm_python(3)							 Python Reference						     dpm_python(3)

NAME
dpm - Python interface to the DPM SYNOPSIS
import dpm DESCRIPTION
The dpm module permits you to access the DPM client interface from python programs. The dpm module is a swig wrapping of the standard C interface. For detailed descriptions of each function see the individual man page of each function. There follows a series of examples of how to use selected functions and how to retrieve the information returned by them: Examples are listing the replicas of a given entry, reading the content of a directory, getting and setting ACLs. etc. EXAMPLE
#!/usr/bin/python """ # Using the dpns_readdirxr method """ import sys import dpm name = "/dpm/cern.ch/home/dteam/"; dir = dpm.dpns_opendirg(name,"") if (dir == None) or (dir == 0): err_num = dpm.cvar.serrno err_string = dpm.sstrerror(err_num) print "Error while looking for " + name + ": Error " + str(err_num) + " (" + err_string + ")" sys.exit(1) while 1: read_pt = dpm.dpns_readdirxr(dir,"") if (read_pt == None) or (read_pt == 0): break entry, list = read_pt print entry.d_name try: for i in range(len(list)): print " ==> %s" % list[i].sfn except TypeError, x: print " ==> None" dpm.dpns_closedir(dir) EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpns_getlinks method """ result, list = dpm.dpns_getlinks("/dpm/cern.ch/home/dteam/file.test", "") print result print len(list) if (result == 0): for i in list: print i.path EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpns_getreplica method """ result, list = dpm.dpns_getreplica("/dpm/cern.ch/home/dteam/file.test", "", "") print result print len(list) if (result == 0): for i in list: print i.host print i.sfn EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpns_getacl and dpns_setacl methods to add a user ACL """ nentries, acls_list = dpm.dpns_getacl("/dpm/cern.ch/home/dteam/file.test", dpm.CA_MAXACLENTRIES) print nentries print len(acls_list) for i in acls_list: print i.a_type print i.a_id print i.a_perm # When adding a first ACL for a given user, you also need to add the mask # When adding the second user ACL, it is not necessary anymore acl_user = dpm.dpns_acl() acl_mask = dpm.dpns_acl() acl_user.a_type=2 # 2 corresponds to CNS_ACL_USER acl_user.a_id=18701 # user id acl_user.a_perm=5 acl_mask.a_type=5 # 5 corresponds to CNS_ACL_MASK acl_mask.a_id=0 # no user id specified acl_mask.a_perm=5 acls_list.append(acl_user) acls_list.append(acl_mask) res = dpm.dpns_setacl("/dpm/cern.ch/home/dteam/file.test", acls_list) if res == 0: print "OK" else: err_num = dpm.cvar.serrno err_string = dpm.sstrerror(err_num) print "There was an error : Error " + str(err_num) + " (" + err_string + ")" sys.exit(1) EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpns_getacl and dpns_setacl methods to remove a user ACL """ nentries, acls_list = dpm.dpns_getacl("/dpm/cern.ch/home/dteam/file.test", dpm.CA_MAXACLENTRIES) # Note : you cannot remove the owner ACL (i.e. for CNS_ACL_USER_OBJ type) if # ====== ACLs for other users exist. If all the other user ACLs are deleted, # ====== the owner ACL is automatically removed. for i in acls_list: print i.a_type print i.a_id print i.a_perm del acls_list[1] # delete a given user ACL from the list of ACLs res = dpm.dpns_setacl("/dpm/cern.ch/home/dteam/file.test", acls_list) if res == 0: print "OK" else: err_num = dpm.cvar.serrno err_string = dpm.sstrerror(err_num) print "There was an error : Error " + str(err_num) + " (" + err_string + ")" sys.exit(1) EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpns_getusrmap method """ result, list = dpm.dpns_getusrmap() print result print len(list) if (result == 0): for i in list: print i.userid + " " + i.username EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpns_getgrpmap method """ result, list = dpm.dpns_getgrpmap() print result print len(list) if (result == 0): for i in list: print i.gid + " " + i.groupname EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_addfs method """ result = dpm.dpm_addfs("mypool", "mydiskserver.domain.com", "/mountpoint", dpm.FS_READONLY) print result EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_modifyfs method """ result = dpm.dpm_modifyfs("mydiskserver.domain.com", "/mountpoint", dpm.FS_READONLY) print result EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_rmfs method """ result = dpm.dpm_rmfs("mypool", "mydiskserver.domain.com", "/mountpoint") print result EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_addpool method """ dpmpool = dpm.dpm_pool() dpmpool.poolname = "mypool" dpmpool.defsize = 209715200 dpmpool.def_lifetime = 604800 dpmpool.defpintime = 604800 dpmpool.max_lifetime = 604800 dpmpool.max_pintime = 604800 dpmpool.nbgids = 1 dpmpool.gids = [0] dpmpool.ret_policy = 'R' dpmpool.s_type = 'D' result = dpm.dpm_addpool(dpmpool) print result EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_modifypool method """ dpmpool = dpm.dpm_pool() dpmpool.poolname = "mypool" dpmpool.defsize = 209715200 dpmpool.def_lifetime = 604800 dpmpool.defpintime = 604800 dpmpool.max_lifetime = 604800 dpmpool.max_pintime = 604800 dpmpool.nbgids = 1 dpmpool.gids = [0] dpmpool.ret_policy = 'R' dpmpool.s_type = 'D' result = dpm.dpm_modifypool(dpmpool) print result EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_rmpool method """ result = dpm.dpm_rmpool("mypool") print result EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_getpoolfs method """ result,list = dpm.dpm_getpoolfs("mypool") print result print len(list) if (result == 0): for i in list: print "POOL " + i.poolname + " SERVER " + i.server + " FS " + i.fs + " CAPACITY " + i.capacity + " FREE " + i.free EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_getpools method """ result,list = dpm.dpm_getpools() print result print len(list) if (result == 0): for i in list: print "POOL " + i.poolname + " CAPACITY " + i.capacity + " FREE " + i.free EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_getprotocols method """ result,list = dpm.dpm_getprotocols() print result print len(list) if (result == 0): for i in list: print i EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_getspacemd method """ result, list = dpm.dpm_getspacemd(["myspacetoken"]) print result print len(list) if (result == 0): for i in list: print "TYPE " + i.s_type + " SPACETOKEN " i.s_token + " USERTOKEN " + i.u_token + " TOTAL " + i.t_space + " GUARANTUEED " + i.g_space + " UNUSED " + i.u_space + " POOL " + i.poolname EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_getspacetoken method """ result, list = dpm.dpm_getspacetoken("myspacetokendesc") print result print len(list) if (result == 0): for i in list: print i EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_reservespace method """ result,actual_s_type,actual_t_space,actual_g_space,actual_lifetime,s_token = dpm.dpm_reservespace('D', "myspacetokendesc", 'R', 'O', 209715200, 209715200, 2592000, 0, "mypoolname") print result if (result == 0): print "TYPE " + actual_s_type + " TOTAL " + actual_t_space + " GUARANTEED " + actual_g_space + " LIFETIME " + actual_lifetime + " TOKEN " + s_token EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_updatespace method """ result,actual_t_space,actual_g_space,actual_lifetime = dpm.dpm_updatespace("myspacetoken", 209715200, 209715200, 2592000) print result if (result == 0): print " TOTAL " + actual_t_space + " GUARANTEED " + actual_g_space + " LIFETIME " + actual_lifetime EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_releasespace method """ result = dpm.dpm_releasespace("myspacetoken", 0) print result EXAMPLE
#!/usr/bin/python import dpm """ # Using the dpm_ping method """ result,info = dpm.dpm_ping("mydpmserver.domain.com") print result if (result == 0): print info KNOWN BUGS
The current interface to the dpns_getcwd(3), dpns_readlink(3), dpns_seterrbuf(3) requires the passing of str object which is modified to contain the result (in a similar way to the C functions, which accept a buffer). However this breaks the immutability of python str. This will be changed in the future. SEE ALSO
DPM C interface man pages DPM
$Date: 2010-02-04 13:08:39 +0100 (Thu, 04 Feb 2010) $ dpm_python(3)
All times are GMT -4. The time now is 02:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy