TypeError:'file'对象的描述符'readlines'需要一个参数

时间:2015-04-13 17:55:57

标签: python readlines

每次运行此代码时都会出现此错误,有人可以帮助我

我想获取网址并在我的网址列表中使用它在文本文件中  sewa.txt

这是代码

#encoding: utf-8
import random  
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC
import time

usr = ('')
pwd = ('')
poo =unicode ("","utf-8")
driver = webdriver.Firefox()
# or you can use Chrome(executable_path="/usr/bin/chromedriver")
driver.get('https://m.facebook.com/groups/192674874113111/')
assert "Facebook" in driver.title
elem = driver.find_element_by_name("email")
elem.send_keys(usr)
elem = driver.find_element_by_name("pass")
elem.send_keys(pwd)
elem.send_keys(Keys.RETURN)
time.sleep(22)
File=open('/home/sharkawey/Desktop/sewa','r');
for line in file.readlines():
    driver.get(line)
    elem = driver.find_element_by_name("lgc_view_photo")
    elem.send_keys(Keys.RETURN)
    time.sleep(15)
    driver.find_element_by_name("file1").send_keys("/media/sharkawey/THE HELL/2.jpg")

    elem = driver.find_element_by_name("xc_message")
    elem.send_keys(poo)
    elem = driver.find_element_by_name("photo_upload")
    elem.send_keys(Keys.RETURN)

这是错误

TypeError: descriptor 'readlines' of 'file' object needs an argument

1 个答案:

答案 0 :(得分:0)

你需要使用它,

for line in File.readlines():

由于您声明的文件对象为File而不是file。 Python是一种区分大小写的语言,在引用变量时需要小心。

OR

或者你可以使用for line in File:,因为文件对象本身就是一个迭代器。