1

I want to store the multiple urls into a single variable 'URLs'. Those URLs is made up from three parts,'urlp1' ,'n'and 'urlp2', which you can see in the code below.

urlp1 = "https://www.proteinatlas.org/" 

URLs = []
for cancer in cancer_list:

    urlp2 = "/pathology/tissue/" + cancer[1]
    f = cancer[0]

    try:
        df1 = pd.read_csv(rootPath + f + ".csv", header=0);
    except Exception as e:
        print("File " + f + " doesn't exist")
        print(str(e))
        sys.exit()

    gene_matrix = df1.as_matrix()
    number_matrix = gene_matrix[:,0]
    gene_cancer = number_matrix.tolist()
    # print(gene_cancer)
    np_clean = [x for x in gene_cancer if str(x) != 'nan']


    for n in np_clean:

        URL = urlp1 + n + urlp2
        URLs.append(URL)
        #print(URLs)

So how can I store all the output into URLs = ["URL1", "URL2", "URL3", ...] ?

Thanks for help.

Rujun Guan
  • 57
  • 5
  • **What are you getting when you `print(URLs)`?** Also please note that you should `print(URLs)` **outside** of the `for` loop to see the full result. Maybe you just want to print the array like this?: https://stackoverflow.com/questions/11178061/print-list-without-brackets-in-a-single-row – adelriosantiago Dec 28 '17 at 09:01

1 Answers1

0

Sorry, small mistake. Just call the print(URLs)outside for loop will solve.

Rujun Guan
  • 57
  • 5