这篇文章主要围绕Python获得正确的行尾和python获取行数展开,旨在为您提供一份详细的参考资料。我们将全面介绍Python获得正确的行尾的优缺点,解答python获取行数的相关问题,同时也会为您
这篇文章主要围绕Python获得正确的行尾和python 获取行数展开,旨在为您提供一份详细的参考资料。我们将全面介绍Python获得正确的行尾的优缺点,解答python 获取行数的相关问题,同时也会为您带来android – 没有在onTouch中获得正确的x y值、arcgis python获得字段唯一值、c# – 如何获得正确的字符串文本?、cmake find_package找到正确的Python3但找不到正确的PythonLib-如何指定路径?的实用方法。
本文目录一览:- Python获得正确的行尾(python 获取行数)
- android – 没有在onTouch中获得正确的x y值
- arcgis python获得字段唯一值
- c# – 如何获得正确的字符串文本?
- cmake find_package找到正确的Python3但找不到正确的PythonLib-如何指定路径?
Python获得正确的行尾(python 获取行数)
是否有一种简单的方法来获取当前操作系统使用的行尾类型?
答案1
小编典典如果您对以文本模式打开的文件进行操作,那么正确的是所有换行符都显示为“\n
”。否则,您正在寻找os.linesep
。
从http://docs.python.org/library/os.html:
os。 Lineep
在当前平台上用于分隔(或终止)行的字符串。这可以是单个字符,例如对于POSIX是’\ n’,也可以是多个字符,例如对于Windows是’\ r \
n’。写入以文本模式打开的文件时,请不要使用os.linesep作为行终止符(默认);在所有平台上都使用一个’\ n’代替。
android – 没有在onTouch中获得正确的x y值
我想在屏幕上拖动时移动图像,但ACTION_MOVE中的x和y值不正确.我在ACTION_MOVE中打印了x和y值.在每个替代中,它打印正确的x和y值.
public boolean onTouch(View v, MotionEvent event) {
ImageView view = (ImageView) v;
float x=0;
float y=0;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
x=event.getX();
y=event.getY();
System.out.println("x= "+x+" y="+y);
int width = 100, height = 100;
lp = new AbsoluteLayout.LayoutParams(width, height, (int) (x), (int) (y));
break;
}
mLayout.updateViewLayout(view, lp);
return true;
}
这是我的代码.印刷输出是:
01-17 10:31:11.721: I/System.out(3983): x= 71.0 y=91.0
01-17 10:31:11.746: I/System.out(3983): x= 102.0 y=24.0
01-17 10:31:11.776: I/System.out(3983): x= 72.0 y=91.0
01-17 10:31:11.806: I/System.out(3983): x= 103.0 y=24.0
01-17 10:31:11.826: I/System.out(3983): x= 73.0 y=91.0
01-17 10:31:11.851: I/System.out(3983): x= 104.0 y=24.0
01-17 10:31:11.871: I/System.out(3983): x= 74.0 y=91.0
01-17 10:31:11.896: I/System.out(3983): x= 105.0 y=24.0
01-17 10:31:11.921: I/System.out(3983): x= 75.0 y=91.0
01-17 10:31:11.941: I/System.out(3983): x= 107.0 y=24.0
01-17 10:31:11.957: I/System.out(3983): x= 76.0 y=90.0
01-17 10:31:11.976: I/System.out(3983): x= 109.0 y=24.0
01-17 10:31:11.996: I/System.out(3983): x= 77.0 y=90.0
01-17 10:31:12.026: I/System.out(3983): x= 110.0 y=24.0
01-17 10:31:12.056: I/System.out(3983): x= 78.0 y=90.0
01-17 10:31:12.101: I/System.out(3983): x= 111.0 y=24.0
01-17 10:31:12.131: I/System.out(3983): x= 79.0 y=89.0
01-17 10:31:12.186: I/System.out(3983): x= 112.0 y=24.0
01-17 10:31:12.231: I/System.out(3983): x= 80.0 y=89.0
01-17 10:31:12.276: I/System.out(3983): x= 113.0 y=24.0
01-17 10:31:12.296: I/System.out(3983): x= 80.0 y=88.0
01-17 10:31:12.316: I/System.out(3983): x= 114.0 y=24.0
01-17 10:31:12.336: I/System.out(3983): x= 81.0 y=88.0
替代点是正确的.但它是如何发生的?我怎么解决这个问题?
解决方法:
如果你检查这个question的答案,他说视图可能有一个内置的触摸事件,可能会干扰你的触摸事件.检查您的视图是否有.
arcgis python获得字段唯一值
arcgis python获得字段唯一值
# Import native arcgisscripting module
import arcgisscripting, sys
# Create the geoprocessor object
gp = arcgisscripting.create(9.3)
# Table and field name inputs
inTable = sys.argv[1]
inField = sys.argv[2]
rows = gp.SearchCursor(inTable)
row = rows.Next()
# Create an empty list
uniqueList = []
while row:
# If the value is not already in the list, append it
if row.GetValue(inField) not in uniqueList:
uniqueList.append(row.GetValue(inField))
row = rows.Next()
# Sort the list alphanumerically
uniqueList.sort()
print uniqueList
========================================
# -*- coding: cp936 -*-
import arcpy
import os
import sys
inTable = arcpy.GetParameterAsText(0)
inField = arcpy.GetParameterAsText(1)
rows = arcpy.SearchCursor(inTable)
# Create an empty list gisoracle
uniqueList = []
for row in rows:
# If the value is not already in the list, append it
if row.getValue(inField) not in uniqueList:
uniqueList.append(row.getValue(inField))
# Sort the list alphanumerically
#uniqueList.sort()
arcpy.AddMessage("个数: " + str(len(uniqueList)))
# -*- coding: cp936 -*-
import arcpy
import os
import sys
def getuniqueValue(inTable,inField):
rows = arcpy.SearchCursor(inTable)
# Create an empty list
uniqueList = []
for row in rows:
# If the value is not already in the list, append it by gisoracle
if row.getValue(inField) not in uniqueList:
uniqueList.append(row.getValue(inField))
return uniqueList
inTable = arcpy.GetParameterAsText(0)
inField = arcpy.GetParameterAsText(1)
uniqueList=getuniqueValue(inTable,inField)
arcpy.AddMessage("个数: " + str(len(uniqueList)))
c# – 如何获得正确的字符串文本?
string originalString = "\u0605\u04c3\u5000\u0000\u5000\ufd00\u4400\ud500\u7600\ud300\u4f00\ubc00\u0c00\u2d00\u4000\ue400\u0e00\u7400\u4800\ub700\u1d00\u1300\ue900\u6000\u4c00\ufb00\u9900\u3900\ud900\u6700\uae00\ueb00\u8f00\u2800\u0200\ub300\u5c00\ufe00\u0100\u3d00\u9100\u3000\u0300\u1600\u0100\u7000\u6200\u8e00\u1d00\u8e00\u6200\ua900\u6300\uc800\u0900\ub700\ub000\u6000\ue400\u9200\u3f00\u9100\u8d00\uef00\u3600\u0100\u9e00\u0081";
如果我在cs文件中对其进行硬编码,我可以在调试模式下看到它显示正确的字符,但如果我在文件中写入了确切的字符串并尝试读取它,则会显示字符串,因为它在文件.
TextReader tr = new StreamReader("c:\\test.txt"); string tmpString = tr.ReadLine(); tr.Close(); byte[] array = Encoding.Unicode.GetBytes(tmpString ); string finalResult = Encoding.Unicode.GetString(array);
如何使finalResult字符串具有正确的unicode字符?
提前致谢
贡萨洛
编辑:已经尝试过放置
TextReader tr = new StreamReader("c:\\test.txt",Encoding.Unicode);
但是角色与正确的角色不同.
解决方法
\u0605\u04c3\u5000\u0000\u5000\ufd00\u4400\ud500\u7600\ud300\u4f00
\ubc00\u0c00\u2d00\u4000\ue400\u0e00\u7400\u4800\ub700\u1d00\u1300
\ue900\u6000\u4c00\ufb00\u9900\u3900\ud900\u6700\uae00\ueb00\u8f00
\u2800\u0200\ub300\u5c00\ufe00\u0100\u3d00\u9100\u3000\u0300\u1600
\u0100\u7000\u6200\u8e00\u1d00\u8e00\u6200\ua900\u6300\uc800\u0900
\ub700\ub000\u6000\ue400\u9200\u3f00\u9100\u8d00\uef00\u3600\u0100\u9e00\u0081
如果是这样,您需要将每个序列转换为其对应的unicode字符
string originalString = "\u0605\u04c3\u5000\u0000\u5000\ufd00\u4400\ud500\u7600\ud300\u4f00\ubc00\u0c00\u2d00\u4000\ue400\u0e00\u7400\u4800\ub700\u1d00\u1300\ue900\u6000\u4c00\ufb00\u9900\u3900\ud900\u6700\uae00\ueb00\u8f00\u2800\u0200\ub300\u5c00\ufe00\u0100\u3d00\u9100\u3000\u0300\u1600\u0100\u7000\u6200\u8e00\u1d00\u8e00\u6200\ua900\u6300\uc800\u0900\ub700\ub000\u6000\ue400\u9200\u3f00\u9100\u8d00\uef00\u3600\u0100\u9e00\u0081"; string tmpString = "\\u0605\\u04c3\\u5000\\u0000\\u5000\\ufd00\\u4400\\ud500\\u7600\\ud300\\u4f00\\ubc00\\u0c00\\u2d00\\u4000\\ue400\\u0e00\\u7400\\u4800\\ub700\\u1d00\\u1300\\ue900\\u6000\\u4c00\\ufb00\\u9900\\u3900\\ud900\\u6700\\uae00\\ueb00\\u8f00\\u2800\\u0200\\ub300\\u5c00\\ufe00\\u0100\\u3d00\\u9100\\u3000\\u0300\\u1600\\u0100\\u7000\\u6200\\u8e00\\u1d00\\u8e00\\u6200\\ua900\\u6300\\uc800\\u0900\\ub700\\ub000\\u6000\\ue400\\u9200\\u3f00\\u9100\\u8d00\\uef00\\u3600\\u0100\\u9e00\\u0081"; string finalResult = Regex.Replace(tmpString,@"\\u(....)",match => ((char)int.Parse(match.Groups[1].Value,System.Globalization.NumberStyles.Hexnumber)).ToString());
cmake find_package找到正确的Python3但找不到正确的PythonLib-如何指定路径?
如何解决cmake find_package找到正确的Python3但找不到正确的PythonLib-如何指定路径??
我如何指定cmake仅应在特定的conda环境中搜索python?
我使用cmake -B build
运行以下CMakeLists.txt:
project(FindPythonProblem)
cmake_minimum_required(VERSION 3.18)
find_package (python3 3.6 EXACT required)
if (python3_FOUND)
message (STATUS "python3 found")
endif ()
find_package (python3 3.6 EXACT required COMPONENTS Interpreter)
if (python3_Interpreter_FOUND)
message (STATUS "python3 Interpreter found")
endif ()
find_package (PythonLibs 3.6 required)
if (PYTHONLIBS_FOUND)
message (STATUS "PythonLibs found")
endif ()
相关的输出是
-- Found python3: C:/Miniconda3/envs/forboost/python.exe (found suitable exact version "3.6.12") found components: Interpreter
-- python3 found
-- python3 Interpreter found
-- Found PythonLibs: C:/Miniconda3/libs/python37.lib (found suitable version "3.7.4",minimum required is "3.6")
-- PythonLibs found
虽然在conda环境forboost
中找到了Python 3.6,但相应的PythonLib却找不到conda环境forboost
的3.6版本。我如何指定cmake仅应在conda环境中搜索以增强效果?
find_package (PythonLibs 3.6 EXACT required)
行将导致错误,因为找不到合适的版本。
有关更多信息:C:/Miniconda3
中有一个python 3.7,C:/Miniconda3/envs/forboost
中有一个我想使用的python 3.6。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
今天关于Python获得正确的行尾和python 获取行数的分享就到这里,希望大家有所收获,若想了解更多关于android – 没有在onTouch中获得正确的x y值、arcgis python获得字段唯一值、c# – 如何获得正确的字符串文本?、cmake find_package找到正确的Python3但找不到正确的PythonLib-如何指定路径?等相关知识,可以在本站进行查询。
本文标签: