当前位置: 首页>>代码示例>>Python>>正文


Python py3compat.u函数代码示例

本文整理汇总了Python中spyderlib.py3compat.u函数的典型用法代码示例。如果您正苦于以下问题:Python u函数的具体用法?Python u怎么用?Python u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了u函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_data

 def process_data(self, text, colsep=u("\t"), rowsep=u("\n"),
                  transpose=False, skiprows=0, comments='#'):
     """Put data into table model"""
     data = self._shape_text(text, colsep, rowsep, transpose, skiprows,
                             comments)
     self._model = PreviewTableModel(data)
     self.setModel(self._model)
开发者ID:dhirschfeld,项目名称:spyderlib,代码行数:7,代码来源:importwizard.py

示例2: open_data

 def open_data(self, text, colsep=u("\t"), rowsep=u("\n"),
               transpose=False, skiprows=0, comments='#'):
     """Open clipboard text as table"""
     if pd:
         self.pd_text = text
         self.pd_info = dict(sep=colsep, lineterminator=rowsep,
             skiprows=skiprows,comment=comments)
     self._table_view.process_data(text, colsep, rowsep, transpose,
                                   skiprows, comments)
开发者ID:dhirschfeld,项目名称:spyderlib,代码行数:9,代码来源:importwizard.py

示例3: test

def test():
    """Array editor test"""
    _app = qapplication()
    
    arr = np.array(["kjrekrjkejr"])
    print("out:", test_edit(arr, "string array"))
    from spyderlib.py3compat import u
    arr = np.array([u("kjrekrjkejr")])
    print("out:", test_edit(arr, "unicode array"))
    arr = np.ma.array([[1, 0], [1, 0]], mask=[[True, False], [False, False]])
    print("out:", test_edit(arr, "masked array"))
    arr = np.zeros((2, 2), {'names': ('red', 'green', 'blue'),
                           'formats': (np.float32, np.float32, np.float32)})
    print("out:", test_edit(arr, "record array"))
    arr = np.array([(0, 0.0), (0, 0.0), (0, 0.0)],
                   dtype=[(('title 1', 'x'), '|i1'),
                          (('title 2', 'y'), '>f4')])
    print("out:", test_edit(arr, "record array with titles"))
    arr = np.random.rand(5, 5)
    print("out:", test_edit(arr, "float array",
                            xlabels=['a', 'b', 'c', 'd', 'e']))
    arr = np.round(np.random.rand(5, 5)*10)+\
                   np.round(np.random.rand(5, 5)*10)*1j
    print("out:", test_edit(arr, "complex array",
                            xlabels=np.linspace(-12, 12, 5),
                            ylabels=np.linspace(-12, 12, 5)))
    arr_in = np.array([True, False, True])
    print("in:", arr_in)
    arr_out = test_edit(arr_in, "bool array")
    print("out:", arr_out)
    print(arr_in is arr_out)
    arr = np.array([1, 2, 3], dtype="int8")
    print("out:", test_edit(arr, "int array"))
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:33,代码来源:arrayeditor.py

示例4: get_selected_text

 def get_selected_text(self):
     """
     Return text selected by current text cursor, converted in unicode
     
     Replace the unicode line separator character \u2029 by 
     the line separator characters returned by get_line_separator
     """
     return to_text_string(self.textCursor().selectedText()).replace(u("\u2029"),
                                                  self.get_line_separator())
开发者ID:arvindchari88,项目名称:newGitTest,代码行数:9,代码来源:mixins.py

示例5: kernel_and_frontend_match

 def kernel_and_frontend_match(self, connection_file):
     # Determine kernel version
     ci = get_connection_info(connection_file, unpack=True,
                              profile='default')
     if u('control_port') in ci:
         kernel_ver = '>=1.0'
     else:
         kernel_ver = '<1.0'
     # is_module_installed checks if frontend version agrees with the
     # kernel one
     return programs.is_module_installed('IPython', version=kernel_ver)
开发者ID:Poneyo,项目名称:spyderlib,代码行数:11,代码来源:ipythonconsole.py

示例6: on_enter

 def on_enter(self, command):
     """on_enter"""
     if self.profile:
         # Simple profiling test
         t0 = time()
         for _ in range(10):
             self.execute_command(command)
         self.insert_text(u("\n<Δt>=%dms\n") % (1e2*(time()-t0)))
         self.new_prompt(self.interpreter.p1)
     else:
         self.execute_command(command)
     self.__flush_eventqueue()
开发者ID:rthouvenin,项目名称:spyder,代码行数:12,代码来源:internalshell.py

示例7: get_text

 def get_text(self, position_from, position_to):
     """
     Return text between *position_from* and *position_to*
     Positions may be positions or 'sol', 'eol', 'sof', 'eof' or 'cursor'
     """
     cursor = self.__select_text(position_from, position_to)
     text = to_text_string(cursor.selectedText())
     if text:
         while text.endswith("\n"):
             text = text[:-1]
         while text.endswith(u("\u2029")):
             text = text[:-1]
     return text
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:13,代码来源:mixins.py

示例8: _shape_text

 def _shape_text(self, text, colsep=u("\t"), rowsep=u("\n"),
                 transpose=False, skiprows=0, comments='#'):
     """Decode the shape of the given text"""
     assert colsep != rowsep
     out = []
     text_rows = text.split(rowsep)[skiprows:]
     for row in text_rows:
         stripped = to_text_string(row).strip()
         if len(stripped) == 0 or stripped.startswith(comments):
             continue
         line = to_text_string(row).split(colsep)
         line = [try_to_parse(to_text_string(x)) for x in line]
         out.append(line)
     # Replace missing elements with np.nan's or None's
     if programs.is_module_installed('numpy'):
         from numpy import nan
         out = list(zip_longest(*out, fillvalue=nan))
     else:
         out = list(zip_longest(*out, fillvalue=None))
     # Tranpose the last result to get the expected one
     out = [[r[col] for r in out] for col in range(len(out[0]))]
     if transpose:
         return [[r[col] for r in out] for col in range(len(out[0]))]
     return out
开发者ID:dhirschfeld,项目名称:spyderlib,代码行数:24,代码来源:importwizard.py

示例9: text

    def text(self, encoding=None, errors='strict'):
        r""" Open this file, read it in, return the content as a string.

        This uses 'U' mode in Python 2.3 and later, so '\r\n' and '\r'
        are automatically translated to '\n'.

        Optional arguments:

        encoding - The Unicode encoding (or character set) of
            the file.  If present, the content of the file is
            decoded and returned as a unicode object; otherwise
            it is returned as an 8-bit str.
        errors - How to handle Unicode errors; see help(str.decode)
            for the options.  Default is 'strict'.
        """
        if encoding is None:
            # 8-bit
            f = self.open(_textmode)
            try:
                return f.read()
            finally:
                f.close()
        else:
            # Unicode
            f = codecs.open(self, 'r', encoding, errors)
            # (Note - Can't use 'U' mode here, since codecs.open
            # doesn't support 'U' mode, even in Python 2.3.)
            try:
                t = f.read()
            finally:
                f.close()
            return (t.replace(u('\r\n'), u('\n'))
                     .replace(u('\r\x85'), u('\n'))
                     .replace(u('\r'), u('\n'))
                     .replace(u('\x85'), u('\n'))
                     .replace(u('\u2028'), u('\n')))
开发者ID:dhirschfeld,项目名称:spyderlib,代码行数:36,代码来源:path.py

示例10: get

 def get(self):
     valuelist = []
     for index, (label, value) in enumerate(self.data):
         field = self.widgets[index]
         if label is None:
             # Separator / Comment
             continue
         elif tuple_to_qfont(value) is not None:
             value = field.get_font()
         elif is_text_string(value):
             if isinstance(field, QTextEdit):
                 value = to_text_string(field.toPlainText()
                                        ).replace(u("\u2029"), os.linesep)
             else:
                 value = to_text_string(field.text())
         elif isinstance(value, (list, tuple)):
             index = int(field.currentIndex())
             if isinstance(value[0], int):
                 # Return an int index, if initialization was an int
                 value = index
             else:
                 value = value[index+1]
                 if isinstance(value, (list, tuple)):
                     value = value[0]
         elif isinstance(value, bool):
             value = field.checkState() == Qt.Checked
         elif isinstance(value, float):
             value = float(field.text())
         elif isinstance(value, int):
             value = int(field.value())
         elif isinstance(value, datetime.datetime):
             value = field.dateTime()
             try:
                 value = value.toPyDateTime()  # PyQt
             except AttributeError:
                 value = value.toPython()  # PySide
         elif isinstance(value, datetime.date):
             value = field.date()
             try:
                 value = value.toPyDate()  # PyQt
             except AttributeError:
                 value = value.toPython()  # PySide
         else:
             value = eval(str(field.text()))
         valuelist.append(value)
     return valuelist
开发者ID:ming-hai,项目名称:spyder,代码行数:46,代码来源:formlayout.py

示例11: get_owner

    def get_owner(self):
        r""" Return the name of the owner of this file or directory.

        This follows symbolic links.

        On Windows, this returns a name of the form ur'DOMAIN\User Name'.
        On Windows, a group can own a file or directory.
        """
        if os.name == 'nt':
            if win32security is None:
                raise Exception("path.owner requires win32all to be installed")
            desc = win32security.GetFileSecurity(
                self, win32security.OWNER_SECURITY_INFORMATION)
            sid = desc.GetSecurityDescriptorOwner()
            account, domain, typecode = win32security.LookupAccountSid(None, sid)
            return domain + u('\\') + account
        else:
            if pwd is None:
                raise NotImplementedError("path.owner is not implemented on this platform.")
            st = self.stat()
            return pwd.getpwuid(st.st_uid).pw_name
开发者ID:dhirschfeld,项目名称:spyderlib,代码行数:21,代码来源:path.py

示例12: get_col_sep

 def get_col_sep(self):
     """Return the column separator"""
     if self.tab_btn.isChecked():
         return u("\t")
     return to_text_string(self.line_edt.text())
开发者ID:dhirschfeld,项目名称:spyderlib,代码行数:5,代码来源:importwizard.py

示例13: save_auto


def save_auto(data, filename):
    """Save data into filename, depending on file extension"""
    pass


if __name__ == "__main__":
    from spyderlib.py3compat import u
    import datetime

    testdict = {"d": 1, "a": np.random.rand(10, 10), "b": [1, 2]}
    testdate = datetime.date(1945, 5, 8)
    example = {
        "str": "kjkj kj k j j kj k jkj",
        "unicode": u("éù"),
        "list": [1, 3, [4, 5, 6], "kjkj", None],
        "tuple": ([1, testdate, testdict], "kjkj", None),
        "dict": testdict,
        "float": 1.2233,
        "array": np.random.rand(4000, 400),
        "empty_array": np.array([]),
        "date": testdate,
        "datetime": datetime.datetime(1945, 5, 8),
    }
    import time

    t0 = time.time()
    save_dictionary(example, "test.spydata")
    print(" Data saved in %.3f seconds" % (time.time() - t0))
    t0 = time.time()
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:29,代码来源:iofuncs.py

示例14: IOFunctions

iofunctions = IOFunctions()
iofunctions.setup()


def save_auto(data, filename):
    """Save data into filename, depending on file extension"""
    pass


if __name__ == "__main__":
    from spyderlib.py3compat import u
    import datetime
    testdict = {'d': 1, 'a': np.random.rand(10, 10), 'b': [1, 2]}
    testdate = datetime.date(1945, 5, 8)
    example = {'str': 'kjkj kj k j j kj k jkj',
               'unicode': u('éù'),
               'list': [1, 3, [4, 5, 6], 'kjkj', None],
               'tuple': ([1, testdate, testdict], 'kjkj', None),
               'dict': testdict,
               'float': 1.2233,
               'array': np.random.rand(4000, 400),
               'empty_array': np.array([]),
               'date': testdate,
               'datetime': datetime.datetime(1945, 5, 8),
               }
    import time
    t0 = time.time()
    save_dictionary(example, "test.spydata")
    print(" Data saved in %.3f seconds" % (time.time()-t0))
    t0 = time.time()
    example2, ok = load_dictionary("test.spydata")
开发者ID:JamesLinus,项目名称:spyder,代码行数:31,代码来源:iofuncs.py

示例15: setup

 def setup(self):
     for label, value in self.data:
         if DEBUG_FORMLAYOUT:
             print("value:", value)
         if label is None and value is None:
             # Separator: (None, None)
             self.formlayout.addRow(QLabel(" "), QLabel(" "))
             self.widgets.append(None)
             continue
         elif label is None:
             # Comment
             self.formlayout.addRow(QLabel(value))
             self.widgets.append(None)
             continue
         elif tuple_to_qfont(value) is not None:
             field = FontLayout(value, self)
         elif text_to_qcolor(value).isValid():
             field = ColorLayout(QColor(value), self)
         elif is_text_string(value):
             if '\n' in value:
                 for linesep in (os.linesep, '\n'):
                     if linesep in value:
                         value = value.replace(linesep, u("\u2029"))
                 field = QTextEdit(value, self)
             else:
                 field = QLineEdit(value, self)
         elif isinstance(value, (list, tuple)):
             value = list(value)  # in case this is a tuple
             selindex = value.pop(0)
             field = QComboBox(self)
             if isinstance(value[0], (list, tuple)):
                 keys = [ key for key, _val in value ]
                 value = [ val for _key, val in value ]
             else:
                 keys = value
             field.addItems(value)
             if selindex in value:
                 selindex = value.index(selindex)
             elif selindex in keys:
                 selindex = keys.index(selindex)
             elif not isinstance(selindex, int):
                 print("Warning: '%s' index is invalid (label: "\
                       "%s, value: %s)" % (selindex, label, value),
                       file=STDERR)
                 selindex = 0
             field.setCurrentIndex(selindex)
         elif isinstance(value, bool):
             field = QCheckBox(self)
             field.setCheckState(Qt.Checked if value else Qt.Unchecked)
         elif isinstance(value, float):
             field = QLineEdit(repr(value), self)
             field.setValidator(QDoubleValidator(field))
             dialog = self.get_dialog()
             dialog.register_float_field(field)
             field.textChanged.connect(lambda text: dialog.update_buttons())
         elif isinstance(value, int):
             field = QSpinBox(self)
             field.setRange(-1e9, 1e9)
             field.setValue(value)
         elif isinstance(value, datetime.datetime):
             field = QDateTimeEdit(self)
             field.setDateTime(value)
         elif isinstance(value, datetime.date):
             field = QDateEdit(self)
             field.setDate(value)
         else:
             field = QLineEdit(repr(value), self)
         self.formlayout.addRow(label, field)
         self.widgets.append(field)
开发者ID:ming-hai,项目名称:spyder,代码行数:69,代码来源:formlayout.py


注:本文中的spyderlib.py3compat.u函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。