首页 \ 问答 \ Python解释器如何查找类型?(How does Python interpreter look for types?)

Python解释器如何查找类型?(How does Python interpreter look for types?)

如果我写的东西如下:

>>> a = float()

Python解释器如何知道在哪里查找类型'float'?

我知道'float'是一个在Lib / types.py中定义的变量,它引用了内置类型types.FloatType 。 但是,解释器如何为脚本构建所有可能类型的完整列表(包括用户定义和导入模块定义)? 它看起来在哪些地方? 如何在Python脚本中构建这样的列表呢?


If I write something like:

>>> a = float()

how does Python interpreter know where to look for type 'float'?

I know that 'float' is a variable defined in Lib/types.py and refers to built-in type types.FloatType. But how does the interpreter build a complete list of all possible types for a script (including user-defined and imported-module-defined)? Which places does it look in? And what do I do to build such a list inside a Python script?


原文:
更新时间:2022-09-03 17:09

最满意答案

- 更新---将此部分替换为下面提供的代码区域

   Dim x2 As Integer = 0 ' Keep a track of index
   For Each i As Integer In ListBox1.Items
        ' create a Point with index as x and the actual value of list item as y
         s.Points.AddXY(Convert.toDouble(x2), Convert.toDouble(i))
         x2 = x2+1
   Next

图表应该是这样的

 Chart1.Series.Clear() 'Empty your chart of any previous values

 Chart1.Titles.Add("My Line chart") 'Add a Title

 Dim s As New Series 'Create a new series
 s.Name = "My Line" 'Series name

 s.ChartType = SeriesChartType.Line 'Chart type

 'Most important part, the points to plot
 'Points START
  s.Points.AddXY(1, 2)
  s.Points.AddXY(3, 4)
  s.Points.AddXY(5, 9)
 'Points END

 'Add the series to the Chart1 control
 Chart1.Series.Add(s)

我不确定你为什么使用RichTextBox1。 如果你正在收集用户输入(x,y)点,那么你将需要构建你的点。 使用TextBox控件而不是RichText ,只要使用给定的描述就足够了。

用这个替换上面代码中的Points位

'Assume the user is entering value/numbers separated by ","
'Use the input as both x and y
'e.g 1,2,3,...
Dim textCont As String = TextBox.Text
Dim boxValues As String() = textCont.Split(New Char() {","})
For Each item In boxValues
 s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
 s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
 s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
Next

就您提供的代码而言,本示例中没有使用ListBox控件或引用。

AddXY(双人间,双人间)


--Update--- Replace this part in the Points region of code provided below

   Dim x2 As Integer = 0 ' Keep a track of index
   For Each i As Integer In ListBox1.Items
        ' create a Point with index as x and the actual value of list item as y
         s.Points.AddXY(Convert.toDouble(x2), Convert.toDouble(i))
         x2 = x2+1
   Next

A chart should be something like this

 Chart1.Series.Clear() 'Empty your chart of any previous values

 Chart1.Titles.Add("My Line chart") 'Add a Title

 Dim s As New Series 'Create a new series
 s.Name = "My Line" 'Series name

 s.ChartType = SeriesChartType.Line 'Chart type

 'Most important part, the points to plot
 'Points START
  s.Points.AddXY(1, 2)
  s.Points.AddXY(3, 4)
  s.Points.AddXY(5, 9)
 'Points END

 'Add the series to the Chart1 control
 Chart1.Series.Add(s)

I'm not sure why you are using a RichTextBox1. If you are gathering user input (x,y) points then you will need to construct your points. Use a TextBox control instead of RichText, it should suffice, with the given description.

Replace the Points bit in the above code with this

'Assume the user is entering value/numbers separated by ","
'Use the input as both x and y
'e.g 1,2,3,...
Dim textCont As String = TextBox.Text
Dim boxValues As String() = textCont.Split(New Char() {","})
For Each item In boxValues
 s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
 s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
 s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
Next

As far as the code you've provided, there is no ListBox control or reference to use in this example.

AddXY(Double,Double)

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。