Sponsored Content
Full Discussion: Python Regex List Creation
Top Forums Programming Python Regex List Creation Post 302950884 by metallica1973 on Wednesday 29th of July 2015 05:01:08 PM
Old 07-29-2015
Python Regex List Creation

Here is a snippet of my code:
Code:
    blahblahblah...
    blah[]
    for link in goodies.soup.find_all('a'):
       blah.append(link.get('href'))
       blah=list(set(blah))

which gives my list of urls. So now I use a regex to search for the relevant urls which I want in a list:
Code:
     for r in blah:
     capture=re.findall(r'https://.*', r)
     print (capture)

which prints the results as:
Code:
    []
    ['https://blah.org/plugins/blahblahblahblah/']
    []
    []
    ['https://blah.org/plugins/blahblahblah/']

What I am trying to do is create a list from these results. When I attempt to do this, I always run into a brickwall:
Code:
    for r in blah:
        capture=re.findall(r'https://.*', r)
        purls=[]
        purls.append(capture)
    purls
    [[]]
    for r in blah:
        capture=re.findall(r'https://.*', r)
        purls=[]
           for a in capture:
               purls.append(a)
    purls
    []

This is the closest thing I could come up with:
Code:
    for r in blah:
         capture=re.findall(r'https://.*', r)
         rolos=capture[:]
         print rolos
    []
    ['https://blah.org/plugins/blahblahblahblah/']
    []
    []
    ['https://blah.org/plugins/blahblahblah/']
    whos
    rolos           list      n=0

But as you can see, it didnt create the list???? What am I doing wrong and how can this be accomplished ?

---------- Post updated at 05:01 PM ---------- Previous update was at 04:34 PM ----------

so it turned out to be the +=, which is the increment operator
Code:
    for r in blah:
      capture=re.findall(r'https://.*', r)
      rolos+=capture[:]

Thanks to dslackw for providing this insane resolution. I still cant believe it.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python Regex

I have the below string and regex. However I cant understand why it works the way it does. IP has been changed for safety ;) String = NowSMS Error Report. Error initializing SMSC Interface 'SMPP - 10.15.8.10:17600'. Interface is not available. Regex = (.+\.)\s(.+) I get two... (1 Reply)
Discussion started by: barney34
1 Replies

2. UNIX for Dummies Questions & Answers

List directories with given string, sort by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, which directories name has given particular string. Example: Directories with name "Build" 2. On the output of 1. list the directories by creation date as sort order. I tried with; find . -type d -name "Build*" ... (3 Replies)
Discussion started by: Siva SQL
3 Replies

3. Red Hat

Dynamic case creation based on output list from a command

I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (1 Reply)
Discussion started by: slatoms
1 Replies

4. Shell Programming and Scripting

Dynamic case creation based on output list from a command

I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (7 Replies)
Discussion started by: slatoms
7 Replies

5. Shell Programming and Scripting

Python Newbie Question Regex

I starting teaching myself python and am stuck on trying to understand why I am not getting the output that I want. Long story short, I am using PDB for debugging and here my function in which I am having my issue: import re ... ... ... def find_all_flvs(url): soup =... (1 Reply)
Discussion started by: metallica1973
1 Replies

6. Programming

Python Reading Individual files and Regex through them

As a newbie to Python, I am trying to write a script in which is will add all the log files (*.log) from within a directory to a list, open the files and search for an ip using a regex and single it out (appending the ip's to the list). So far, I have: import re, os def list_files() content = ... (4 Replies)
Discussion started by: metallica1973
4 Replies

7. Shell Programming and Scripting

Python Regex Removing One Too Many...

Well, I'm a python noob and my last post here I was introduced to Regex. I thought this would be easy since I knew Regex with Bash. However, I've been banging my head a while to extract an ip address from ifconfig with this: #!/usr/bin/python import re import subprocess from subprocess... (5 Replies)
Discussion started by: Azrael
5 Replies

8. Shell Programming and Scripting

List creation - Grep a line in a file with a script name

Hi, I have a list file which has script names in them. Some scripts take lists as parameters which inturn have script names. This is basically for sequencing the job run. Eg: List1: test1.ksh test2.ksh test2.lst test3.ksh test3.lst test4.ksh test2.lst: test21.ksh test23.ksh... (7 Replies)
Discussion started by: member2014
7 Replies

9. Shell Programming and Scripting

How can i sort this listing in PYTHON by folder creation?

Is there anything i can do about this code? I need to sort it by folder creation, the newest will be first ... thx :) for dirname in postme: dirname = os.path.abspath(dirname) if dirname: ... (2 Replies)
Discussion started by: ZerO13
2 Replies

10. Shell Programming and Scripting

Python with Regex and Excel

Hello I have a big excel file for Ticket Data Analysis. The idea is to make meaningful insight from Resolution Field. Now as people write whatever they feel like while resolving the ticket it makes quite a task. 1. They may or may not tag it with something like below within the resolution... (1 Reply)
Discussion started by: radioactive9
1 Replies
explain_select_or_die(3)				     Library Functions Manual					  explain_select_or_die(3)

NAME
explain_select_or_die - blah blah and report errors SYNOPSIS
#include <libexplain/select.h> void explain_select_or_die(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); DESCRIPTION
The explain_select_or_die function is used to call the select(2) system call. On failure an explanation will be printed to stderr, obtained from explain_select(3), and then the process terminates by calling exit(EXIT_FAILURE). This function is intended to be used in a fashion similar to the following example: explain_select_or_die(nfds, readfds, writefds, exceptfds, timeout); nfds The nfds, exactly as to be passed to the select(2) system call. readfds The readfds, exactly as to be passed to the select(2) system call. writefds The writefds, exactly as to be passed to the select(2) system call. exceptfds The exceptfds, exactly as to be passed to the select(2) system call. timeout The timeout, exactly as to be passed to the select(2) system call. Returns: This function only returns on success. On failure, prints an explanation and exits. SEE ALSO
select(2) blah blah explain_select(3) explain select(2) errors exit(2) terminate the calling process COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_select_or_die(3)
All times are GMT -4. The time now is 03:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy