小编Flu*_*tor的帖子

麻烦连接两个字符串

我在连接两个字符串时遇到了麻烦.这是我的代码:

info = infl.readline()
while True:
    line = infl.readline()
    outfl.write(info + line)
    print info + line
Run Code Online (Sandbox Code Playgroud)

问题是输出出现在两个不同的行上.例如,输出文本如下所示:

490250633800 802788.0 953598.2
802781.968872 953674.839355 193.811523 1 0.126805 -999.000000 -999.000000 -999.000000
Run Code Online (Sandbox Code Playgroud)

我希望两个字符串在同一行.

python string concatenation

1
推荐指数
1
解决办法
1815
查看次数

Python/Tkinter状态栏未正确更新

我用Tkinter在Python(2.7)中开发了一个简单的应用程序.但我的状态栏只是有点工作.这是精简代码:

from Tkinter import *
import os
import sys

def fixFiles():
    inputFilePath= input_dir.get()

    #Build a list of files in a directory
    fileList = os.listdir(inputFilePath)

    #Loop through those files, open the file, do something, close the file
    for filename in fileList:
        infile = open(inputfilepath + "/" + filename,'r')

        #Update the status with the filename
        status_string = 'Status: Working on file: ' + str(filename)
        status.set(status_string)

        for line in infile:
            #Do some stuff here
        infile.close()  

class App:
    def __init__(self, master):
            i = 0 …
Run Code Online (Sandbox Code Playgroud)

python tkinter

1
推荐指数
1
解决办法
3266
查看次数

Python:从文件读取时出现语法错误

我正在读取文件中的数据.数据文件中的大多数数据将被读入并写入输出文件而不进行修改.但是,在某些地方,数据由空白行分隔,该空白行位于其他5个无用行之前.这是我的代码:

#Now loop over the entire file
while True:
testline = infile.readline()
if len(testline) ==0:
    break # EOF
elseif testline == '\n':
    for i in range(0,5)
        testline = infile.readline()
else:
    outfile.write(testline)
Run Code Online (Sandbox Code Playgroud)

我得到以下错误,让我难过:

File "convert.py", line 31
elseif testline == '\n':
              ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?我无法弄清楚我的elseif语句有什么问题.

python syntax file-io

0
推荐指数
2
解决办法
857
查看次数

一些基本的JavaScript的麻烦

我在使用一些基本的javascript时遇到了一些麻烦:

function tank(){
    this.width = 50;
    this.length = 70;
}

function Person(job) {
    this.job = job;
    this.married = true;
}
var tank1 = tank();
console.log(tank1.length);  //returns: Uncaught TypeError: Cannot read property 'length' of undefined

var gabby = new Person("student");
console.log(gabby.married);  //returns: true
Run Code Online (Sandbox Code Playgroud)

第一个console.log不起作用,但第二个console.log工作.我是一个javascript初学者,我不知道为什么长度属性是未定义的.有帮助吗?

javascript

0
推荐指数
1
解决办法
94
查看次数

标签 统计

python ×3

concatenation ×1

file-io ×1

javascript ×1

string ×1

syntax ×1

tkinter ×1