Once you iterate pdf_file
by enumerate
you cannot iterate it again except invoking pdb_file.seek(0)
seek(0) changes the stream position to the beginning
Here’s my modification:
num = 1 for line in pdb_file: num += 1 if "L01" in line: print num break pdb_file.seek(0) # go back to the beginning and then it can be iterated again last_host=int(num) print(last_host-1) for atom in range(0, last_host-1): data = pdb_file.readline() new_pdb_file.write(data)
Related Posts:
- What does enumerate() mean?
- TypeError: ‘float’ object not iterable
- TypeError: ‘list’ object cannot be interpreted as an integer
- ValueError: max() arg is an empty sequence
- python – if not in list
- Pythonic way to combine FOR loop and IF statement
- enumerate() for dictionary in python
- How to iterate through two lists in parallel?
- For loop and ‘numpy.float64’ object is not iterable error
- What does the “x for x in” syntax mean?
- Infinite for loops possible in Python?
- “for loop” with two variables?
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- List append() in for loop
- Python loop counter in a for loop
- “for loop” with two variables?
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade
- Is a Python dictionary an example of a hash table?
- Why does this iterative list-growing code give IndexError: list assignment index out of range?
- Modifing data while using iterrows() does not work
- difference between command prompt and anaconda prompt
- Do I understand os.walk right?
- Converting dictionary to JSON
- Saving and loading objects and using pickle
- numpy: Invalid value encountered in true_divide
- Invalid character in identifier
- Is “from matplotlib import pyplot as plt” == “import matplotlib.pyplot as plt”?
- ‘str’ object does not support item assignment
- What does `ValueError: cannot reindex from a duplicate axis` mean?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- How to print an exception in Python?
- What are “named tuples” in Python?
- What do these operators mean (** , ^ , %, //)? [closed]
- How can I remove a trailing newline?
- Pycharm exit code 0
- How do you split a string in Python with multiple delimiters?
- syntaxError: ‘continue’ not properly in loop
- ValueError: all the input arrays must have same number of dimensions
- Get the data received in a Flask request
- Python function execution
- Where do I find the bashrc file on Mac?
- ValueError: setting an array element with a sequence
- Why does num = 100?
- How do order of operations go on Python?
- Python group by
- IndexError: index 1 is out of bounds for axis 0 with size 1/ForwardEuler
- selenium – chromedriver executable needs to be in PATH
- TypeError: tuple indices must be integers, not str
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- TypeError(“‘bool’ object is not iterable”,) when trying to return a Boolean
- Flask Template Not found
- Making a collatz program automate the boring stuff
- Reverse / invert a dictionary mapping
- using pip3: module “importlib._bootstrap” has no attribute “SourceFileLoader”
- Flask ImportError: No Module Named Flask
- Running an outside program (executable) in Python?
- SyntaxError invalid token
- TypeError: ‘type’ object is not iterable – Iterating over object instances
- How to check the version of scipy
- What does socket binding mean?
- How to strip all whitespace from string
- Python Binomial Coefficient
- Pandas – How to flatten a hierarchical index in columns
- What is the difference between json.load() and json.loads() functions
- Viewing all defined variables
- Difference between two dates in Python
- ImportError: No module named win32com.client
- Error message “Linter pylint is not installed”
- RuntimeWarning: overflow encountered in ubyte_scalars
- Pandas – Drop function error (label not contained in axis)
- Python Requests – No connection adapters
- WindowsError: [Error 126] The specified module could not be found
- Split string using a newline delimiter with Python
- Why am I getting ImportError: No module named pip ‘ right after installing pip?
- No module named urllib3
- How to convert index of a pandas dataframe into a column
- Python requests SSL error – certificate verify failed
- How to know/change current directory in Python shell?
- Trying to run Flask app gives “Address already in use”
- What is a unicode string?
- Remove specific characters from a string in Python
- pandas replace multiple values one column
- How can I make one python file run another? [duplicate]
- Error: No module named ‘fcntl’
- “Can’t convert ‘float’ object to str implicitly”
- Python can’t find file
- Plotting graphs in C++
- ‘MyClass’ object has no attribute ‘__getitem__’
- Can’t install Scipy through pip
- How to run python code in Sublime Text 3?
- Random word generator- Python
- How can I install the Beautiful Soup module on the Mac?
- What is python’s site-packages directory?
- How do I get Flask to run on port 80?
- optional arguments in initializer of python class
- Python convert tuple to string
- Does Python have an immutable list?
- __init__() got an unexpected keyword argument ‘user’
- Create dynamic URLs in Flask with url_for()